Upload part 1 of 2
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- add-edges-to-make-degrees-of-all-nodes-even.json +38 -0
- alice-and-bob-playing-flower-game.json +31 -0
- alternating-groups-i.json +31 -0
- alternating-groups-ii.json +37 -0
- alternating-groups-iii.json +40 -0
- ant-on-the-boundary.json +34 -0
- append-characters-to-string-to-make-subsequence.json +34 -0
- append-k-integers-with-minimal-sum.json +30 -0
- apple-redistribution-into-boxes.json +31 -0
- apply-bitwise-operations-to-make-strings-equal.json +32 -0
- apply-discount-to-prices.json +35 -0
- apply-operations-on-array-to-maximize-sum-of-squares.json +30 -0
- apply-operations-to-an-array.json +31 -0
- apply-operations-to-make-all-array-elements-equal-to-zero.json +30 -0
- apply-operations-to-make-string-empty.json +33 -0
- apply-operations-to-make-two-strings-equal.json +32 -0
- apply-operations-to-maximize-frequency-score.json +31 -0
- apply-operations-to-maximize-score.json +33 -0
- assign-elements-to-groups-with-constraints.json +45 -0
- average-value-of-even-numbers-that-are-divisible-by-three.json +29 -0
- beautiful-towers-i.json +34 -0
- beautiful-towers-ii.json +36 -0
- best-poker-hand.json +36 -0
- bitwise-xor-of-all-pairings.json +29 -0
- buy-two-chocolates.json +30 -0
- calculate-delayed-arrival-time.json +29 -0
- calculate-digit-sum-of-a-string.json +30 -0
- categorize-box-according-to-criteria.json +39 -0
- cells-in-a-range-on-an-excel-sheet.json +35 -0
- check-distances-between-same-letters.json +32 -0
- check-if-array-is-good.json +39 -0
- check-if-bitwise-or-has-trailing-zeros.json +34 -0
- check-if-digits-are-equal-in-string-after-operations-i.json +54 -0
- check-if-digits-are-equal-in-string-after-operations-ii.json +54 -0
- check-if-every-row-and-column-contains-all-numbers.json +30 -0
- check-if-grid-can-be-cut-into-sections.json +41 -0
- check-if-grid-satisfies-conditions.json +36 -0
- check-if-it-is-possible-to-split-array.json +45 -0
- check-if-matrix-is-x-matrix.json +30 -0
- check-if-number-has-equal-digit-count-and-digit-value.json +30 -0
- check-if-point-is-reachable.json +32 -0
- check-if-strings-can-be-made-equal-with-operations-i.json +30 -0
- check-if-strings-can-be-made-equal-with-operations-ii.json +31 -0
- check-if-there-is-a-valid-parentheses-string-path.json +38 -0
- check-if-there-is-a-valid-partition-for-the-array.json +29 -0
- check-if-two-chessboard-squares-have-the-same-color.json +30 -0
- circular-sentence.json +39 -0
- clear-digits.json +31 -0
- closest-equal-element-queries.json +34 -0
- closest-prime-numbers-in-range.json +31 -0
add-edges-to-make-degrees-of-all-nodes-even.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2596,
|
| 3 |
+
"name": "add-edges-to-make-degrees-of-all-nodes-even",
|
| 4 |
+
"difficulty": "Hard",
|
| 5 |
+
"link": "https://leetcode.com/problems/add-edges-to-make-degrees-of-all-nodes-even/",
|
| 6 |
+
"date": "2022-12-11",
|
| 7 |
+
"task_description": "There is an **undirected** graph consisting of `n` nodes numbered from `1` to `n`. You are given the integer `n` and a **2D** array `edges` where `edges[i] = [ai, bi]` indicates that there is an edge between nodes `ai` and `bi`. The graph can be disconnected. You can add **at most** two additional edges (possibly none) to this graph so that there are no repeated edges and no self-loops. Return `true`_ if it is possible to make the degree of each node in the graph even, otherwise return _`false`_._ The degree of a node is the number of edges connected to it. **Example 1:** ``` **Input:** n = 5, edges = [[1,2],[2,3],[3,4],[4,2],[1,4],[2,5]] **Output:** true **Explanation:** The above diagram shows a valid way of adding an edge. Every node in the resulting graph is connected to an even number of edges. ``` **Example 2:** ``` **Input:** n = 4, edges = [[1,2],[3,4]] **Output:** true **Explanation:** The above diagram shows a valid way of adding two edges. ``` **Example 3:** ``` **Input:** n = 4, edges = [[1,2],[1,3],[1,4]] **Output:** false **Explanation:** It is not possible to obtain a valid graph with adding at most 2 edges. ``` **Constraints:** `3 <= n <= 105` `2 <= edges.length <= 105` `edges[i].length == 2` `1 <= ai, bi <= n` `ai != bi` There are no repeated edges.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "n = 5, edges = [[1,2],[2,3],[3,4],[4,2],[1,4],[2,5]]",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "n = 4, edges = [[1,2],[3,4]]",
|
| 17 |
+
"output": "true "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "n = 4, edges = [[1,2],[1,3],[1,4]]",
|
| 22 |
+
"output": "false "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"3 <= n <= 105",
|
| 27 |
+
"2 <= edges.length <= 105",
|
| 28 |
+
"edges[i].length == 2",
|
| 29 |
+
"1 <= ai, bi <= n",
|
| 30 |
+
"ai != bi",
|
| 31 |
+
"There are no repeated edges."
|
| 32 |
+
],
|
| 33 |
+
"python_template": "class Solution(object):\n def isPossible(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: bool\n \"\"\"\n ",
|
| 34 |
+
"java_template": "class Solution {\n public boolean isPossible(int n, List<List<Integer>> edges) {\n \n }\n}",
|
| 35 |
+
"metadata": {
|
| 36 |
+
"func_name": "isPossible"
|
| 37 |
+
}
|
| 38 |
+
}
|
alice-and-bob-playing-flower-game.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3279,
|
| 3 |
+
"name": "alice-and-bob-playing-flower-game",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/alice-and-bob-playing-flower-game/",
|
| 6 |
+
"date": "2024-01-21",
|
| 7 |
+
"task_description": "Alice and Bob are playing a turn-based game on a circular field surrounded by flowers. The circle represents the field, and there are `x` flowers in the clockwise direction between Alice and Bob, and `y` flowers in the anti-clockwise direction between them. The game proceeds as follows: Alice takes the first turn. In each turn, a player must choose either the clockwise or anti-clockwise direction and pick one flower from that side. At the end of the turn, if there are no flowers left at all, the **current** player captures their opponent and wins the game. Given two integers, `n` and `m`, the task is to compute the number of possible pairs `(x, y)` that satisfy the conditions: Alice must win the game according to the described rules. The number of flowers `x` in the clockwise direction must be in the range `[1,n]`. The number of flowers `y` in the anti-clockwise direction must be in the range `[1,m]`. Return _the number of possible pairs_ `(x, y)` _that satisfy the conditions mentioned in the statement_. **Example 1:** ``` **Input:** n = 3, m = 2 **Output:** 3 **Explanation:** The following pairs satisfy conditions described in the statement: (1,2), (3,2), (2,1). ``` **Example 2:** ``` **Input:** n = 1, m = 1 **Output:** 0 **Explanation:** No pairs satisfy the conditions described in the statement. ``` **Constraints:** `1 <= n, m <= 105`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "n = 3, m = 2",
|
| 12 |
+
"output": "3 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "n = 1, m = 1",
|
| 17 |
+
"output": "0 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"Alice must win the game according to the described rules.",
|
| 22 |
+
"The number of flowers x in the clockwise direction must be in the range [1,n].",
|
| 23 |
+
"The number of flowers y in the anti-clockwise direction must be in the range [1,m].",
|
| 24 |
+
"1 <= n, m <= 105"
|
| 25 |
+
],
|
| 26 |
+
"python_template": "class Solution(object):\n def flowerGame(self, n, m):\n \"\"\"\n :type n: int\n :type m: int\n :rtype: int\n \"\"\"\n ",
|
| 27 |
+
"java_template": "class Solution {\n public long flowerGame(int n, int m) {\n \n }\n}",
|
| 28 |
+
"metadata": {
|
| 29 |
+
"func_name": "flowerGame"
|
| 30 |
+
}
|
| 31 |
+
}
|
alternating-groups-i.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3463,
|
| 3 |
+
"name": "alternating-groups-i",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/alternating-groups-i/",
|
| 6 |
+
"date": "2024-06-22",
|
| 7 |
+
"task_description": "There is a circle of red and blue tiles. You are given an array of integers `colors`. The color of tile `i` is represented by `colors[i]`: `colors[i] == 0` means that tile `i` is **red**. `colors[i] == 1` means that tile `i` is **blue**. Every 3 contiguous tiles in the circle with **alternating** colors (the middle tile has a different color from its **left** and **right** tiles) is called an **alternating** group. Return the number of **alternating** groups. **Note** that since `colors` represents a **circle**, the **first** and the **last** tiles are considered to be next to each other. **Example 1:** **Input:** colors = [1,1,1] **Output:** 0 **Explanation:** **Example 2:** **Input:** colors = [0,1,0,0,1] **Output:** 3 **Explanation:** Alternating groups: ******** **Constraints:** `3 <= colors.length <= 100` `0 <= colors[i] <= 1`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "colors = [1,1,1]",
|
| 12 |
+
"output": "0 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "colors = [0,1,0,0,1]",
|
| 17 |
+
"output": "3 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"colors[i] == 0 means that tile i is red.",
|
| 22 |
+
"colors[i] == 1 means that tile i is blue.",
|
| 23 |
+
"3 <= colors.length <= 100",
|
| 24 |
+
"0 <= colors[i] <= 1"
|
| 25 |
+
],
|
| 26 |
+
"python_template": "class Solution(object):\n def numberOfAlternatingGroups(self, colors):\n \"\"\"\n :type colors: List[int]\n :rtype: int\n \"\"\"\n ",
|
| 27 |
+
"java_template": "class Solution {\n public int numberOfAlternatingGroups(int[] colors) {\n \n }\n}",
|
| 28 |
+
"metadata": {
|
| 29 |
+
"func_name": "numberOfAlternatingGroups"
|
| 30 |
+
}
|
| 31 |
+
}
|
alternating-groups-ii.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3483,
|
| 3 |
+
"name": "alternating-groups-ii",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/alternating-groups-ii/",
|
| 6 |
+
"date": "2024-06-22",
|
| 7 |
+
"task_description": "There is a circle of red and blue tiles. You are given an array of integers `colors` and an integer `k`. The color of tile `i` is represented by `colors[i]`: `colors[i] == 0` means that tile `i` is **red**. `colors[i] == 1` means that tile `i` is **blue**. An **alternating** group is every `k` contiguous tiles in the circle with **alternating** colors (each tile in the group except the first and last one has a different color from its **left** and **right** tiles). Return the number of **alternating** groups. **Note** that since `colors` represents a **circle**, the **first** and the **last** tiles are considered to be next to each other. **Example 1:** **Input:** colors = [0,1,0,1,0], k = 3 **Output:** 3 **Explanation:** **** Alternating groups: **Example 2:** **Input:** colors = [0,1,0,0,1,0,1], k = 6 **Output:** 2 **Explanation:** **** Alternating groups: **Example 3:** **Input:** colors = [1,1,0,1], k = 4 **Output:** 0 **Explanation:** **Constraints:** `3 <= colors.length <= 105` `0 <= colors[i] <= 1` `3 <= k <= colors.length`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "colors = [0,1,0,1,0], k = 3",
|
| 12 |
+
"output": "3 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "colors = [0,1,0,0,1,0,1], k = 6",
|
| 17 |
+
"output": "2 "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "colors = [1,1,0,1], k = 4",
|
| 22 |
+
"output": "0 "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"colors[i] == 0 means that tile i is red.",
|
| 27 |
+
"colors[i] == 1 means that tile i is blue.",
|
| 28 |
+
"3 <= colors.length <= 105",
|
| 29 |
+
"0 <= colors[i] <= 1",
|
| 30 |
+
"3 <= k <= colors.length"
|
| 31 |
+
],
|
| 32 |
+
"python_template": "class Solution(object):\n def numberOfAlternatingGroups(self, colors, k):\n \"\"\"\n :type colors: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n ",
|
| 33 |
+
"java_template": "class Solution {\n public int numberOfAlternatingGroups(int[] colors, int k) {\n \n }\n}",
|
| 34 |
+
"metadata": {
|
| 35 |
+
"func_name": "numberOfAlternatingGroups"
|
| 36 |
+
}
|
| 37 |
+
}
|
alternating-groups-iii.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3527,
|
| 3 |
+
"name": "alternating-groups-iii",
|
| 4 |
+
"difficulty": "Hard",
|
| 5 |
+
"link": "https://leetcode.com/problems/alternating-groups-iii/",
|
| 6 |
+
"date": "2024-07-28",
|
| 7 |
+
"task_description": "There are some red and blue tiles arranged circularly. You are given an array of integers `colors` and a 2D integers array `queries`. The color of tile `i` is represented by `colors[i]`: `colors[i] == 0` means that tile `i` is **red**. `colors[i] == 1` means that tile `i` is **blue**. An **alternating** group is a contiguous subset of tiles in the circle with **alternating** colors (each tile in the group except the first and last one has a different color from its adjacent tiles in the group). You have to process queries of two types: `queries[i] = [1, sizei]`, determine the count of **alternating** groups with size `sizei`. `queries[i] = [2, indexi, colori]`, change `colors[indexi]` to `colori`. Return an array `answer` containing the results of the queries of the first type _in order_. **Note** that since `colors` represents a **circle**, the **first** and the **last** tiles are considered to be next to each other. **Example 1:** **Input:** colors = [0,1,1,0,1], queries = [[2,1,0],[1,4]] **Output:** [2] **Explanation:** **** First query: Change `colors[1]` to 0. Second query: Count of the alternating groups with size 4: **Example 2:** **Input:** colors = [0,0,1,0,1,1], queries = [[1,3],[2,3,0],[1,5]] **Output:** [2,0] **Explanation:** First query: Count of the alternating groups with size 3: Second query: `colors` will not change. Third query: There is no alternating group with size 5. **Constraints:** `4 <= colors.length <= 5 * 104` `0 <= colors[i] <= 1` `1 <= queries.length <= 5 * 104` `queries[i][0] == 1` or `queries[i][0] == 2` For all `i` that: `queries[i][0] == 1`: `queries[i].length == 2`, `3 <= queries[i][1] <= colors.length - 1` `queries[i][0] == 2`: `queries[i].length == 3`, `0 <= queries[i][1] <= colors.length - 1`, `0 <= queries[i][2] <= 1`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "colors = [0,1,1,0,1], queries = [[2,1,0],[1,4]]",
|
| 12 |
+
"output": "[2] "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "colors = [0,0,1,0,1,1], queries = [[1,3],[2,3,0],[1,5]]",
|
| 17 |
+
"output": "[2,0] "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"colors[i] == 0 means that tile i is red.",
|
| 22 |
+
"colors[i] == 1 means that tile i is blue.",
|
| 23 |
+
"queries[i] = [1, sizei], determine the count of alternating groups with size sizei.",
|
| 24 |
+
"queries[i] = [2, indexi, colori], change colors[indexi] to colori.",
|
| 25 |
+
"4 <= colors.length <= 5 * 104",
|
| 26 |
+
"0 <= colors[i] <= 1",
|
| 27 |
+
"1 <= queries.length <= 5 * 104",
|
| 28 |
+
"queries[i][0] == 1 or queries[i][0] == 2",
|
| 29 |
+
"For all i that:\n\t\nqueries[i][0] == 1: queries[i].length == 2, 3 <= queries[i][1] <= colors.length - 1\nqueries[i][0] == 2: queries[i].length == 3, 0 <= queries[i][1] <= colors.length - 1, 0 <= queries[i][2] <= 1",
|
| 30 |
+
"queries[i][0] == 1: queries[i].length == 2, 3 <= queries[i][1] <= colors.length - 1",
|
| 31 |
+
"queries[i][0] == 2: queries[i].length == 3, 0 <= queries[i][1] <= colors.length - 1, 0 <= queries[i][2] <= 1",
|
| 32 |
+
"queries[i][0] == 1: queries[i].length == 2, 3 <= queries[i][1] <= colors.length - 1",
|
| 33 |
+
"queries[i][0] == 2: queries[i].length == 3, 0 <= queries[i][1] <= colors.length - 1, 0 <= queries[i][2] <= 1"
|
| 34 |
+
],
|
| 35 |
+
"python_template": "class Solution(object):\n def numberOfAlternatingGroups(self, colors, queries):\n \"\"\"\n :type colors: List[int]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"\n ",
|
| 36 |
+
"java_template": "class Solution {\n public List<Integer> numberOfAlternatingGroups(int[] colors, int[][] queries) {\n \n }\n}",
|
| 37 |
+
"metadata": {
|
| 38 |
+
"func_name": "numberOfAlternatingGroups"
|
| 39 |
+
}
|
| 40 |
+
}
|
ant-on-the-boundary.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3311,
|
| 3 |
+
"name": "ant-on-the-boundary",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/ant-on-the-boundary/",
|
| 6 |
+
"date": "2024-01-28",
|
| 7 |
+
"task_description": "An ant is on a boundary. It sometimes goes **left** and sometimes **right**. You are given an array of **non-zero** integers `nums`. The ant starts reading `nums` from the first element of it to its end. At each step, it moves according to the value of the current element: If `nums[i] < 0`, it moves **left** by `-nums[i]` units. If `nums[i] > 0`, it moves **right** by `nums[i]` units. Return _the number of times the ant **returns** to the boundary._ **Notes:** There is an infinite space on both sides of the boundary. We check whether the ant is on the boundary only after it has moved `|nums[i]|` units. In other words, if the ant crosses the boundary during its movement, it does not count. **Example 1:** ``` **Input:** nums = [2,3,-5] **Output:** 1 **Explanation:** After the first step, the ant is 2 steps to the right of the boundary. After the second step, the ant is 5 steps to the right of the boundary. After the third step, the ant is on the boundary. So the answer is 1. ``` **Example 2:** ``` **Input:** nums = [3,2,-3,-4] **Output:** 0 **Explanation:** After the first step, the ant is 3 steps to the right of the boundary. After the second step, the ant is 5 steps to the right of the boundary. After the third step, the ant is 2 steps to the right of the boundary. After the fourth step, the ant is 2 steps to the left of the boundary. The ant never returned to the boundary, so the answer is 0. ``` **Constraints:** `1 <= nums.length <= 100` `-10 <= nums[i] <= 10` `nums[i] != 0`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [2,3,-5]",
|
| 12 |
+
"output": "1 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [3,2,-3,-4]",
|
| 17 |
+
"output": "0 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"If nums[i] < 0, it moves left by -nums[i] units.",
|
| 22 |
+
"If nums[i] > 0, it moves right by nums[i] units.",
|
| 23 |
+
"There is an infinite space on both sides of the boundary.",
|
| 24 |
+
"We check whether the ant is on the boundary only after it has moved |nums[i]| units. In other words, if the ant crosses the boundary during its movement, it does not count.",
|
| 25 |
+
"1 <= nums.length <= 100",
|
| 26 |
+
"-10 <= nums[i] <= 10",
|
| 27 |
+
"nums[i] != 0"
|
| 28 |
+
],
|
| 29 |
+
"python_template": "class Solution(object):\n def returnToBoundaryCount(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
|
| 30 |
+
"java_template": "class Solution {\n public int returnToBoundaryCount(int[] nums) {\n \n }\n}",
|
| 31 |
+
"metadata": {
|
| 32 |
+
"func_name": "returnToBoundaryCount"
|
| 33 |
+
}
|
| 34 |
+
}
|
append-characters-to-string-to-make-subsequence.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2572,
|
| 3 |
+
"name": "append-characters-to-string-to-make-subsequence",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/append-characters-to-string-to-make-subsequence/",
|
| 6 |
+
"date": "2022-11-20",
|
| 7 |
+
"task_description": "You are given two strings `s` and `t` consisting of only lowercase English letters. Return _the minimum number of characters that need to be appended to the end of _`s`_ so that _`t`_ becomes a **subsequence** of _`s`. A **subsequence** is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. **Example 1:** ``` **Input:** s = \"coaching\", t = \"coding\" **Output:** 4 **Explanation:** Append the characters \"ding\" to the end of s so that s = \"coachingding\". Now, t is a subsequence of s (\"**co**aching**ding**\"). It can be shown that appending any 3 characters to the end of s will never make t a subsequence. ``` **Example 2:** ``` **Input:** s = \"abcde\", t = \"a\" **Output:** 0 **Explanation:** t is already a subsequence of s (\"**a**bcde\"). ``` **Example 3:** ``` **Input:** s = \"z\", t = \"abcde\" **Output:** 5 **Explanation:** Append the characters \"abcde\" to the end of s so that s = \"zabcde\". Now, t is a subsequence of s (\"z**abcde**\"). It can be shown that appending any 4 characters to the end of s will never make t a subsequence. ``` **Constraints:** `1 <= s.length, t.length <= 105` `s` and `t` consist only of lowercase English letters.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"coaching\", t = \"coding\"",
|
| 12 |
+
"output": "4 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"abcde\", t = \"a\"",
|
| 17 |
+
"output": "0 "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "s = \"z\", t = \"abcde\"",
|
| 22 |
+
"output": "5 "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"1 <= s.length, t.length <= 105",
|
| 27 |
+
"s and t consist only of lowercase English letters."
|
| 28 |
+
],
|
| 29 |
+
"python_template": "class Solution(object):\n def appendCharacters(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: int\n \"\"\"\n ",
|
| 30 |
+
"java_template": "class Solution {\n public int appendCharacters(String s, String t) {\n \n }\n}",
|
| 31 |
+
"metadata": {
|
| 32 |
+
"func_name": "appendCharacters"
|
| 33 |
+
}
|
| 34 |
+
}
|
append-k-integers-with-minimal-sum.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2305,
|
| 3 |
+
"name": "append-k-integers-with-minimal-sum",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/append-k-integers-with-minimal-sum/",
|
| 6 |
+
"date": "2022-02-27",
|
| 7 |
+
"task_description": "You are given an integer array `nums` and an integer `k`. Append `k` **unique positive** integers that do **not** appear in `nums` to `nums` such that the resulting total sum is **minimum**. Return_ the sum of the_ `k` _integers appended to_ `nums`. **Example 1:** ``` **Input:** nums = [1,4,25,10,25], k = 2 **Output:** 5 **Explanation:** The two unique positive integers that do not appear in nums which we append are 2 and 3. The resulting sum of nums is 1 + 4 + 25 + 10 + 25 + 2 + 3 = 70, which is the minimum. The sum of the two integers appended is 2 + 3 = 5, so we return 5. ``` **Example 2:** ``` **Input:** nums = [5,6], k = 6 **Output:** 25 **Explanation:** The six unique positive integers that do not appear in nums which we append are 1, 2, 3, 4, 7, and 8. The resulting sum of nums is 5 + 6 + 1 + 2 + 3 + 4 + 7 + 8 = 36, which is the minimum. The sum of the six integers appended is 1 + 2 + 3 + 4 + 7 + 8 = 25, so we return 25. ``` **Constraints:** `1 <= nums.length <= 105` `1 <= nums[i] <= 109` `1 <= k <= 108`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [1,4,25,10,25], k = 2",
|
| 12 |
+
"output": "5 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [5,6], k = 6",
|
| 17 |
+
"output": "25 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"1 <= nums.length <= 105",
|
| 22 |
+
"1 <= nums[i] <= 109",
|
| 23 |
+
"1 <= k <= 108"
|
| 24 |
+
],
|
| 25 |
+
"python_template": "class Solution(object):\n def minimalKSum(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n ",
|
| 26 |
+
"java_template": "class Solution {\n public long minimalKSum(int[] nums, int k) {\n \n }\n}",
|
| 27 |
+
"metadata": {
|
| 28 |
+
"func_name": "minimalKSum"
|
| 29 |
+
}
|
| 30 |
+
}
|
apple-redistribution-into-boxes.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3334,
|
| 3 |
+
"name": "apple-redistribution-into-boxes",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/apple-redistribution-into-boxes/",
|
| 6 |
+
"date": "2024-03-03",
|
| 7 |
+
"task_description": "You are given an array `apple` of size `n` and an array `capacity` of size `m`. There are `n` packs where the `ith` pack contains `apple[i]` apples. There are `m` boxes as well, and the `ith` box has a capacity of `capacity[i]` apples. Return _the **minimum** number of boxes you need to select to redistribute these _`n`_ packs of apples into boxes_. **Note** that, apples from the same pack can be distributed into different boxes. **Example 1:** ``` **Input:** apple = [1,3,2], capacity = [4,3,1,5,2] **Output:** 2 **Explanation:** We will use boxes with capacities 4 and 5. It is possible to distribute the apples as the total capacity is greater than or equal to the total number of apples. ``` **Example 2:** ``` **Input:** apple = [5,5,5], capacity = [2,4,2,7] **Output:** 4 **Explanation:** We will need to use all the boxes. ``` **Constraints:** `1 <= n == apple.length <= 50` `1 <= m == capacity.length <= 50` `1 <= apple[i], capacity[i] <= 50` The input is generated such that it's possible to redistribute packs of apples into boxes.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "apple = [1,3,2], capacity = [4,3,1,5,2]",
|
| 12 |
+
"output": "2 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "apple = [5,5,5], capacity = [2,4,2,7]",
|
| 17 |
+
"output": "4 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"1 <= n == apple.length <= 50",
|
| 22 |
+
"1 <= m == capacity.length <= 50",
|
| 23 |
+
"1 <= apple[i], capacity[i] <= 50",
|
| 24 |
+
"The input is generated such that it's possible to redistribute packs of apples into boxes."
|
| 25 |
+
],
|
| 26 |
+
"python_template": "class Solution(object):\n def minimumBoxes(self, apple, capacity):\n \"\"\"\n :type apple: List[int]\n :type capacity: List[int]\n :rtype: int\n \"\"\"\n ",
|
| 27 |
+
"java_template": "class Solution {\n public int minimumBoxes(int[] apple, int[] capacity) {\n \n }\n}",
|
| 28 |
+
"metadata": {
|
| 29 |
+
"func_name": "minimumBoxes"
|
| 30 |
+
}
|
| 31 |
+
}
|
apply-bitwise-operations-to-make-strings-equal.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2632,
|
| 3 |
+
"name": "apply-bitwise-operations-to-make-strings-equal",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/apply-bitwise-operations-to-make-strings-equal/",
|
| 6 |
+
"date": "2023-01-15",
|
| 7 |
+
"task_description": "You are given two **0-indexed binary** strings `s` and `target` of the same length `n`. You can do the following operation on `s` **any** number of times: Choose two **different** indices `i` and `j` where `0 <= i, j < n`. Simultaneously, replace `s[i]` with (`s[i]` **OR** `s[j]`) and `s[j]` with (`s[i]` **XOR** `s[j]`). For example, if `s = \"0110\"`, you can choose `i = 0` and `j = 2`, then simultaneously replace `s[0]` with (`s[0]` **OR** `s[2]` = `0` **OR** `1` = `1`), and `s[2]` with (`s[0]` **XOR** `s[2]` = `0` **XOR** `1` = `1`), so we will have `s = \"1110\"`. Return `true` _if you can make the string _`s`_ equal to _`target`_, or _`false`_ otherwise_. **Example 1:** ``` **Input:** s = \"1010\", target = \"0110\" **Output:** true **Explanation:** We can do the following operations: - Choose i = 2 and j = 0. We have now s = \"**0**0**1**0\". - Choose i = 2 and j = 1. We have now s = \"0**11**0\". Since we can make s equal to target, we return true. ``` **Example 2:** ``` **Input:** s = \"11\", target = \"00\" **Output:** false **Explanation:** It is not possible to make s equal to target with any number of operations. ``` **Constraints:** `n == s.length == target.length` `2 <= n <= 105` `s` and `target` consist of only the digits `0` and `1`.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"1010\", target = \"0110\"",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"11\", target = \"00\"",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"Choose two different indices i and j where 0 <= i, j < n.",
|
| 22 |
+
"Simultaneously, replace s[i] with (s[i] OR s[j]) and s[j] with (s[i] XOR s[j]).",
|
| 23 |
+
"n == s.length == target.length",
|
| 24 |
+
"2 <= n <= 105",
|
| 25 |
+
"s and target consist of only the digits 0 and 1."
|
| 26 |
+
],
|
| 27 |
+
"python_template": "class Solution(object):\n def makeStringsEqual(self, s, target):\n \"\"\"\n :type s: str\n :type target: str\n :rtype: bool\n \"\"\"\n ",
|
| 28 |
+
"java_template": "class Solution {\n public boolean makeStringsEqual(String s, String target) {\n \n }\n}",
|
| 29 |
+
"metadata": {
|
| 30 |
+
"func_name": "makeStringsEqual"
|
| 31 |
+
}
|
| 32 |
+
}
|
apply-discount-to-prices.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2373,
|
| 3 |
+
"name": "apply-discount-to-prices",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/apply-discount-to-prices/",
|
| 6 |
+
"date": "2022-05-22",
|
| 7 |
+
"task_description": "A **sentence** is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign `'$'`. A word represents a **price** if it is a sequence of digits preceded by a dollar sign. For example, `\"$100\"`, `\"$23\"`, and `\"$6\"` represent prices while `\"100\"`, `\"$\"`, and `\"$1e5\"` do not. You are given a string `sentence` representing a sentence and an integer `discount`. For each word representing a price, apply a discount of `discount%` on the price and **update** the word in the sentence. All updated prices should be represented with **exactly two** decimal places. Return _a string representing the modified sentence_. Note that all prices will contain **at most** `10` digits. **Example 1:** ``` **Input:** sentence = \"there are $1 $2 and 5$ candies in the shop\", discount = 50 **Output:** \"there are $0.50 $1.00 and 5$ candies in the shop\" **Explanation:** The words which represent prices are \"$1\" and \"$2\". - A 50% discount on \"$1\" yields \"$0.50\", so \"$1\" is replaced by \"$0.50\". - A 50% discount on \"$2\" yields \"$1\". Since we need to have exactly 2 decimal places after a price, we replace \"$2\" with \"$1.00\". ``` **Example 2:** ``` **Input:** sentence = \"1 2 $3 4 $5 $6 7 8$ $9 $10$\", discount = 100 **Output:** \"1 2 $0.00 4 $0.00 $0.00 7 8$ $0.00 $10$\" **Explanation:** Applying a 100% discount on any price will result in 0. The words representing prices are \"$3\", \"$5\", \"$6\", and \"$9\". Each of them is replaced by \"$0.00\". ``` **Constraints:** `1 <= sentence.length <= 105` `sentence` consists of lowercase English letters, digits, `' '`, and `'$'`. `sentence` does not have leading or trailing spaces. All words in `sentence` are separated by a single space. All prices will be **positive** numbers without leading zeros. All prices will have **at most** `10` digits. `0 <= discount <= 100`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "sentence = \"there are $1 $2 and 5$ candies in the shop\", discount = 50",
|
| 12 |
+
"output": "\"there are $0.50 $1.00 and 5$ candies in the shop\" "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "sentence = \"1 2 $3 4 $5 $6 7 8$ $9 $10$\", discount = 100",
|
| 17 |
+
"output": "\"1 2 $0.00 4 $0.00 $0.00 7 8$ $0.00 $10$\" "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"For example, \"$100\", \"$23\", and \"$6\" represent prices while \"100\", \"$\", and \"$1e5\" do not.",
|
| 22 |
+
"1 <= sentence.length <= 105",
|
| 23 |
+
"sentence consists of lowercase English letters, digits, ' ', and '$'.",
|
| 24 |
+
"sentence does not have leading or trailing spaces.",
|
| 25 |
+
"All words in sentence are separated by a single space.",
|
| 26 |
+
"All prices will be positive numbers without leading zeros.",
|
| 27 |
+
"All prices will have at most 10 digits.",
|
| 28 |
+
"0 <= discount <= 100"
|
| 29 |
+
],
|
| 30 |
+
"python_template": "class Solution(object):\n def discountPrices(self, sentence, discount):\n \"\"\"\n :type sentence: str\n :type discount: int\n :rtype: str\n \"\"\"\n ",
|
| 31 |
+
"java_template": "class Solution {\n public String discountPrices(String sentence, int discount) {\n \n }\n}",
|
| 32 |
+
"metadata": {
|
| 33 |
+
"func_name": "discountPrices"
|
| 34 |
+
}
|
| 35 |
+
}
|
apply-operations-on-array-to-maximize-sum-of-squares.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3153,
|
| 3 |
+
"name": "apply-operations-on-array-to-maximize-sum-of-squares",
|
| 4 |
+
"difficulty": "Hard",
|
| 5 |
+
"link": "https://leetcode.com/problems/apply-operations-on-array-to-maximize-sum-of-squares/",
|
| 6 |
+
"date": "2023-10-01",
|
| 7 |
+
"task_description": "You are given a **0-indexed** integer array `nums` and a **positive** integer `k`. You can do the following operation on the array **any** number of times: Choose any two distinct indices `i` and `j` and **simultaneously** update the values of `nums[i]` to `(nums[i] AND nums[j])` and `nums[j]` to `(nums[i] OR nums[j])`. Here, `OR` denotes the bitwise `OR` operation, and `AND` denotes the bitwise `AND` operation. You have to choose `k` elements from the final array and calculate the sum of their **squares**. Return _the **maximum** sum of squares you can achieve_. Since the answer can be very large, return it **modulo** `109 + 7`. **Example 1:** ``` **Input:** nums = [2,6,5,8], k = 2 **Output:** 261 **Explanation:** We can do the following operations on the array: - Choose i = 0 and j = 3, then change nums[0] to (2 AND 8) = 0 and nums[3] to (2 OR 8) = 10. The resulting array is nums = [0,6,5,10]. - Choose i = 2 and j = 3, then change nums[2] to (5 AND 10) = 0 and nums[3] to (5 OR 10) = 15. The resulting array is nums = [0,6,0,15]. We can choose the elements 15 and 6 from the final array. The sum of squares is 152 + 62 = 261. It can be shown that this is the maximum value we can get. ``` **Example 2:** ``` **Input:** nums = [4,5,4,7], k = 3 **Output:** 90 **Explanation:** We do not need to apply any operations. We can choose the elements 7, 5, and 4 with a sum of squares: 72 + 52 + 42 = 90. It can be shown that this is the maximum value we can get. ``` **Constraints:** `1 <= k <= nums.length <= 105` `1 <= nums[i] <= 109`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [2,6,5,8], k = 2",
|
| 12 |
+
"output": "261 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [4,5,4,7], k = 3",
|
| 17 |
+
"output": "90 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"Choose any two distinct indices i and j and simultaneously update the values of nums[i] to (nums[i] AND nums[j]) and nums[j] to (nums[i] OR nums[j]). Here, OR denotes the bitwise OR operation, and AND denotes the bitwise AND operation.",
|
| 22 |
+
"1 <= k <= nums.length <= 105",
|
| 23 |
+
"1 <= nums[i] <= 109"
|
| 24 |
+
],
|
| 25 |
+
"python_template": "class Solution(object):\n def maxSum(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n ",
|
| 26 |
+
"java_template": "class Solution {\n public int maxSum(List<Integer> nums, int k) {\n \n }\n}",
|
| 27 |
+
"metadata": {
|
| 28 |
+
"func_name": "maxSum"
|
| 29 |
+
}
|
| 30 |
+
}
|
apply-operations-to-an-array.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2551,
|
| 3 |
+
"name": "apply-operations-to-an-array",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/apply-operations-to-an-array/",
|
| 6 |
+
"date": "2022-10-30",
|
| 7 |
+
"task_description": "You are given a **0-indexed** array `nums` of size `n` consisting of **non-negative** integers. You need to apply `n - 1` operations to this array where, in the `ith` operation (**0-indexed**), you will apply the following on the `ith` element of `nums`: If `nums[i] == nums[i + 1]`, then multiply `nums[i]` by `2` and set `nums[i + 1]` to `0`. Otherwise, you skip this operation. After performing **all** the operations, **shift** all the `0`'s to the **end** of the array. For example, the array `[1,0,2,0,0,1]` after shifting all its `0`'s to the end, is `[1,2,1,0,0,0]`. Return _the resulting array_. **Note** that the operations are applied **sequentially**, not all at once. **Example 1:** ``` **Input:** nums = [1,2,2,1,1,0] **Output:** [1,4,2,0,0,0] **Explanation:** We do the following operations: - i = 0: nums[0] and nums[1] are not equal, so we skip this operation. - i = 1: nums[1] and nums[2] are equal, we multiply nums[1] by 2 and change nums[2] to 0. The array becomes [1,**4**,**0**,1,1,0]. - i = 2: nums[2] and nums[3] are not equal, so we skip this operation. - i = 3: nums[3] and nums[4] are equal, we multiply nums[3] by 2 and change nums[4] to 0. The array becomes [1,4,0,**2**,**0**,0]. - i = 4: nums[4] and nums[5] are equal, we multiply nums[4] by 2 and change nums[5] to 0. The array becomes [1,4,0,2,**0**,**0**]. After that, we shift the 0's to the end, which gives the array [1,4,2,0,0,0]. ``` **Example 2:** ``` **Input:** nums = [0,1] **Output:** [1,0] **Explanation:** No operation can be applied, we just shift the 0 to the end. ``` **Constraints:** `2 <= nums.length <= 2000` `0 <= nums[i] <= 1000`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [1,2,2,1,1,0]",
|
| 12 |
+
"output": "[1,4,2,0,0,0] "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [0,1]",
|
| 17 |
+
"output": "[1,0] "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation.",
|
| 22 |
+
"For example, the array [1,0,2,0,0,1] after shifting all its 0's to the end, is [1,2,1,0,0,0].",
|
| 23 |
+
"2 <= nums.length <= 2000",
|
| 24 |
+
"0 <= nums[i] <= 1000"
|
| 25 |
+
],
|
| 26 |
+
"python_template": "class Solution(object):\n def applyOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"\n ",
|
| 27 |
+
"java_template": "class Solution {\n public int[] applyOperations(int[] nums) {\n \n }\n}",
|
| 28 |
+
"metadata": {
|
| 29 |
+
"func_name": "applyOperations"
|
| 30 |
+
}
|
| 31 |
+
}
|
apply-operations-to-make-all-array-elements-equal-to-zero.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2878,
|
| 3 |
+
"name": "apply-operations-to-make-all-array-elements-equal-to-zero",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/apply-operations-to-make-all-array-elements-equal-to-zero/",
|
| 6 |
+
"date": "2023-07-02",
|
| 7 |
+
"task_description": "You are given a **0-indexed** integer array `nums` and a positive integer `k`. You can apply the following operation on the array **any** number of times: Choose **any** subarray of size `k` from the array and **decrease** all its elements by `1`. Return `true`_ if you can make all the array elements equal to _`0`_, or _`false`_ otherwise_. A **subarray** is a contiguous non-empty part of an array. **Example 1:** ``` **Input:** nums = [2,2,3,1,1,0], k = 3 **Output:** true **Explanation:** We can do the following operations: - Choose the subarray [2,2,3]. The resulting array will be nums = [**1**,**1**,**2**,1,1,0]. - Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,**1**,**0**,**0**,0]. - Choose the subarray [1,1,1]. The resulting array will be nums = [**0**,**0**,**0**,0,0,0]. ``` **Example 2:** ``` **Input:** nums = [1,3,1,1], k = 2 **Output:** false **Explanation:** It is not possible to make all the array elements equal to 0. ``` **Constraints:** `1 <= k <= nums.length <= 105` `0 <= nums[i] <= 106`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [2,2,3,1,1,0], k = 3",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [1,3,1,1], k = 2",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"Choose any subarray of size k from the array and decrease all its elements by 1.",
|
| 22 |
+
"1 <= k <= nums.length <= 105",
|
| 23 |
+
"0 <= nums[i] <= 106"
|
| 24 |
+
],
|
| 25 |
+
"python_template": "class Solution(object):\n def checkArray(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"\n ",
|
| 26 |
+
"java_template": "class Solution {\n public boolean checkArray(int[] nums, int k) {\n \n }\n}",
|
| 27 |
+
"metadata": {
|
| 28 |
+
"func_name": "checkArray"
|
| 29 |
+
}
|
| 30 |
+
}
|
apply-operations-to-make-string-empty.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3308,
|
| 3 |
+
"name": "apply-operations-to-make-string-empty",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/apply-operations-to-make-string-empty/",
|
| 6 |
+
"date": "2024-02-03",
|
| 7 |
+
"task_description": "You are given a string `s`. Consider performing the following operation until `s` becomes **empty**: For **every** alphabet character from `'a'` to `'z'`, remove the **first** occurrence of that character in `s` (if it exists). For example, let initially `s = \"aabcbbca\"`. We do the following operations: Remove the underlined characters `s = \"**a**a**bc**bbca\"`. The resulting string is `s = \"abbca\"`. Remove the underlined characters `s = \"**ab**b**c**a\"`. The resulting string is `s = \"ba\"`. Remove the underlined characters `s = \"**ba**\"`. The resulting string is `s = \"\"`. Return _the value of the string _`s`_ right **before** applying the **last** operation_. In the example above, answer is `\"ba\"`. **Example 1:** ``` **Input:** s = \"aabcbbca\" **Output:** \"ba\" **Explanation:** Explained in the statement. ``` **Example 2:** ``` **Input:** s = \"abcd\" **Output:** \"abcd\" **Explanation:** We do the following operation: - Remove the underlined characters s = \"**abcd**\". The resulting string is s = \"\". The string just before the last operation is \"abcd\". ``` **Constraints:** `1 <= s.length <= 5 * 105` `s` consists only of lowercase English letters.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"aabcbbca\"",
|
| 12 |
+
"output": "\"ba\" "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"abcd\"",
|
| 17 |
+
"output": "\"abcd\" "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"For every alphabet character from 'a' to 'z', remove the first occurrence of that character in s (if it exists).",
|
| 22 |
+
"Remove the underlined characters s = \"aabcbbca\". The resulting string is s = \"abbca\".",
|
| 23 |
+
"Remove the underlined characters s = \"abbca\". The resulting string is s = \"ba\".",
|
| 24 |
+
"Remove the underlined characters s = \"ba\". The resulting string is s = \"\".",
|
| 25 |
+
"1 <= s.length <= 5 * 105",
|
| 26 |
+
"s consists only of lowercase English letters."
|
| 27 |
+
],
|
| 28 |
+
"python_template": "class Solution(object):\n def lastNonEmptyString(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n ",
|
| 29 |
+
"java_template": "class Solution {\n public String lastNonEmptyString(String s) {\n \n }\n}",
|
| 30 |
+
"metadata": {
|
| 31 |
+
"func_name": "lastNonEmptyString"
|
| 32 |
+
}
|
| 33 |
+
}
|
apply-operations-to-make-two-strings-equal.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3033,
|
| 3 |
+
"name": "apply-operations-to-make-two-strings-equal",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/apply-operations-to-make-two-strings-equal/",
|
| 6 |
+
"date": "2023-10-01",
|
| 7 |
+
"task_description": "You are given two **0-indexed** binary strings `s1` and `s2`, both of length `n`, and a positive integer `x`. You can perform any of the following operations on the string `s1` **any** number of times: Choose two indices `i` and `j`, and flip both `s1[i]` and `s1[j]`. The cost of this operation is `x`. Choose an index `i` such that `i < n - 1` and flip both `s1[i]` and `s1[i + 1]`. The cost of this operation is `1`. Return _the **minimum** cost needed to make the strings _`s1`_ and _`s2`_ equal, or return _`-1`_ if it is impossible._ **Note** that flipping a character means changing it from `0` to `1` or vice-versa. **Example 1:** ``` **Input:** s1 = \"1100011000\", s2 = \"0101001010\", x = 2 **Output:** 4 **Explanation:** We can do the following operations: - Choose i = 3 and apply the second operation. The resulting string is s1 = \"110**11**11000\". - Choose i = 4 and apply the second operation. The resulting string is s1 = \"1101**00**1000\". - Choose i = 0 and j = 8 and apply the first operation. The resulting string is s1 = \"**0**1010010**1**0\" = s2. The total cost is 1 + 1 + 2 = 4. It can be shown that it is the minimum cost possible. ``` **Example 2:** ``` **Input:** s1 = \"10110\", s2 = \"00011\", x = 4 **Output:** -1 **Explanation:** It is not possible to make the two strings equal. ``` **Constraints:** `n == s1.length == s2.length` `1 <= n, x <= 500` `s1` and `s2` consist only of the characters `'0'` and `'1'`.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s1 = \"1100011000\", s2 = \"0101001010\", x = 2",
|
| 12 |
+
"output": "4 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s1 = \"10110\", s2 = \"00011\", x = 4",
|
| 17 |
+
"output": "-1 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"Choose two indices i and j, and flip both s1[i] and s1[j]. The cost of this operation is x.",
|
| 22 |
+
"Choose an index i such that i < n - 1 and flip both s1[i] and s1[i + 1]. The cost of this operation is 1.",
|
| 23 |
+
"n == s1.length == s2.length",
|
| 24 |
+
"1 <= n, x <= 500",
|
| 25 |
+
"s1 and s2 consist only of the characters '0' and '1'."
|
| 26 |
+
],
|
| 27 |
+
"python_template": "class Solution(object):\n def minOperations(self, s1, s2, x):\n \"\"\"\n :type s1: str\n :type s2: str\n :type x: int\n :rtype: int\n \"\"\"\n ",
|
| 28 |
+
"java_template": "class Solution {\n public int minOperations(String s1, String s2, int x) {\n \n }\n}",
|
| 29 |
+
"metadata": {
|
| 30 |
+
"func_name": "minOperations"
|
| 31 |
+
}
|
| 32 |
+
}
|
apply-operations-to-maximize-frequency-score.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3196,
|
| 3 |
+
"name": "apply-operations-to-maximize-frequency-score",
|
| 4 |
+
"difficulty": "Hard",
|
| 5 |
+
"link": "https://leetcode.com/problems/apply-operations-to-maximize-frequency-score/",
|
| 6 |
+
"date": "2023-12-10",
|
| 7 |
+
"task_description": "You are given a **0-indexed** integer array `nums` and an integer `k`. You can perform the following operation on the array **at most** `k` times: Choose any index `i` from the array and **increase** or **decrease** `nums[i]` by `1`. The score of the final array is the **frequency** of the most frequent element in the array. Return _the **maximum** score you can achieve_. The frequency of an element is the number of occurences of that element in the array. **Example 1:** ``` **Input:** nums = [1,2,6,4], k = 3 **Output:** 3 **Explanation:** We can do the following operations on the array: - Choose i = 0, and increase the value of nums[0] by 1. The resulting array is [2,2,6,4]. - Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,3]. - Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,2]. The element 2 is the most frequent in the final array so our score is 3. It can be shown that we cannot achieve a better score. ``` **Example 2:** ``` **Input:** nums = [1,4,4,2,4], k = 0 **Output:** 3 **Explanation:** We cannot apply any operations so our score will be the frequency of the most frequent element in the original array, which is 3. ``` **Constraints:** `1 <= nums.length <= 105` `1 <= nums[i] <= 109` `0 <= k <= 1014`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [1,2,6,4], k = 3",
|
| 12 |
+
"output": "3 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [1,4,4,2,4], k = 0",
|
| 17 |
+
"output": "3 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"Choose any index i from the array and increase or decrease nums[i] by 1.",
|
| 22 |
+
"1 <= nums.length <= 105",
|
| 23 |
+
"1 <= nums[i] <= 109",
|
| 24 |
+
"0 <= k <= 1014"
|
| 25 |
+
],
|
| 26 |
+
"python_template": "class Solution(object):\n def maxFrequencyScore(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n ",
|
| 27 |
+
"java_template": "class Solution {\n public int maxFrequencyScore(int[] nums, long k) {\n \n }\n}",
|
| 28 |
+
"metadata": {
|
| 29 |
+
"func_name": "maxFrequencyScore"
|
| 30 |
+
}
|
| 31 |
+
}
|
apply-operations-to-maximize-score.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3001,
|
| 3 |
+
"name": "apply-operations-to-maximize-score",
|
| 4 |
+
"difficulty": "Hard",
|
| 5 |
+
"link": "https://leetcode.com/problems/apply-operations-to-maximize-score/",
|
| 6 |
+
"date": "2023-08-06",
|
| 7 |
+
"task_description": "You are given an array `nums` of `n` positive integers and an integer `k`. Initially, you start with a score of `1`. You have to maximize your score by applying the following operation at most `k` times: Choose any **non-empty** subarray `nums[l, ..., r]` that you haven't chosen previously. Choose an element `x` of `nums[l, ..., r]` with the highest **prime score**. If multiple such elements exist, choose the one with the smallest index. Multiply your score by `x`. Here, `nums[l, ..., r]` denotes the subarray of `nums` starting at index `l` and ending at the index `r`, both ends being inclusive. The **prime score** of an integer `x` is equal to the number of distinct prime factors of `x`. For example, the prime score of `300` is `3` since `300 = 2 * 2 * 3 * 5 * 5`. Return _the **maximum possible score** after applying at most _`k`_ operations_. Since the answer may be large, return it modulo `109 + 7`. **Example 1:** ``` **Input:** nums = [8,3,9,3,8], k = 2 **Output:** 81 **Explanation:** To get a score of 81, we can apply the following operations: - Choose subarray nums[2, ..., 2]. nums[2] is the only element in this subarray. Hence, we multiply the score by nums[2]. The score becomes 1 * 9 = 9. - Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 1, but nums[2] has the smaller index. Hence, we multiply the score by nums[2]. The score becomes 9 * 9 = 81. It can be proven that 81 is the highest score one can obtain. ``` **Example 2:** ``` **Input:** nums = [19,12,14,6,10,18], k = 3 **Output:** 4788 **Explanation:** To get a score of 4788, we can apply the following operations: - Choose subarray nums[0, ..., 0]. nums[0] is the only element in this subarray. Hence, we multiply the score by nums[0]. The score becomes 1 * 19 = 19. - Choose subarray nums[5, ..., 5]. nums[5] is the only element in this subarray. Hence, we multiply the score by nums[5]. The score becomes 19 * 18 = 342. - Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 2, but nums[2] has the smaller index. Hence, we multipy the score by nums[2]. The score becomes 342 * 14 = 4788. It can be proven that 4788 is the highest score one can obtain. ``` **Constraints:** `1 <= nums.length == n <= 105` `1 <= nums[i] <= 105` `1 <= k <= min(n * (n + 1) / 2, 109)`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [8,3,9,3,8], k = 2",
|
| 12 |
+
"output": "81 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [19,12,14,6,10,18], k = 3",
|
| 17 |
+
"output": "4788 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"Choose any non-empty subarray nums[l, ..., r] that you haven't chosen previously.",
|
| 22 |
+
"Choose an element x of nums[l, ..., r] with the highest prime score. If multiple such elements exist, choose the one with the smallest index.",
|
| 23 |
+
"Multiply your score by x.",
|
| 24 |
+
"1 <= nums.length == n <= 105",
|
| 25 |
+
"1 <= nums[i] <= 105",
|
| 26 |
+
"1 <= k <= min(n * (n + 1) / 2, 109)"
|
| 27 |
+
],
|
| 28 |
+
"python_template": "class Solution(object):\n def maximumScore(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n ",
|
| 29 |
+
"java_template": "class Solution {\n public int maximumScore(List<Integer> nums, int k) {\n \n }\n}",
|
| 30 |
+
"metadata": {
|
| 31 |
+
"func_name": "maximumScore"
|
| 32 |
+
}
|
| 33 |
+
}
|
assign-elements-to-groups-with-constraints.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3760,
|
| 3 |
+
"name": "assign-elements-to-groups-with-constraints",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/assign-elements-to-groups-with-constraints/",
|
| 6 |
+
"date": "2025-02-02",
|
| 7 |
+
"task_description": "You are given an integer array `groups`, where `groups[i]` represents the size of the `ith` group. You are also given an integer array `elements`. Your task is to assign **one** element to each group based on the following rules: An element at index `j` can be assigned to a group `i` if `groups[i]` is **divisible** by `elements[j]`. If there are multiple elements that can be assigned, assign the element with the **smallest index** `j`. If no element satisfies the condition for a group, assign -1 to that group. Return an integer array `assigned`, where `assigned[i]` is the index of the element chosen for group `i`, or -1 if no suitable element exists. **Note**: An element may be assigned to more than one group. **Example 1:** **Input:** groups = [8,4,3,2,4], elements = [4,2] **Output:** [0,0,-1,1,0] **Explanation:** `elements[0] = 4` is assigned to groups 0, 1, and 4. `elements[1] = 2` is assigned to group 3. Group 2 cannot be assigned any element. **Example 2:** **Input:** groups = [2,3,5,7], elements = [5,3,3] **Output:** [-1,1,0,-1] **Explanation:** `elements[1] = 3` is assigned to group 1. `elements[0] = 5` is assigned to group 2. Groups 0 and 3 cannot be assigned any element. **Example 3:** **Input:** groups = [10,21,30,41], elements = [2,1] **Output:** [0,1,0,1] **Explanation:** `elements[0] = 2` is assigned to the groups with even values, and `elements[1] = 1` is assigned to the groups with odd values. **Constraints:** `1 <= groups.length <= 105` `1 <= elements.length <= 105` `1 <= groups[i] <= 105` `1 <= elements[i] <= 105`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "groups = [8,4,3,2,4], elements = [4,2]",
|
| 12 |
+
"output": "[0,0,-1,1,0] "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "groups = [2,3,5,7], elements = [5,3,3]",
|
| 17 |
+
"output": "[-1,1,0,-1] "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "groups = [10,21,30,41], elements = [2,1]",
|
| 22 |
+
"output": "[0,1,0,1] "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"An element at index j can be assigned to a group i if groups[i] is divisible by elements[j].",
|
| 27 |
+
"If there are multiple elements that can be assigned, assign the element with the smallest index j.",
|
| 28 |
+
"If no element satisfies the condition for a group, assign -1 to that group.",
|
| 29 |
+
"elements[0] = 4 is assigned to groups 0, 1, and 4.",
|
| 30 |
+
"elements[1] = 2 is assigned to group 3.",
|
| 31 |
+
"Group 2 cannot be assigned any element.",
|
| 32 |
+
"elements[1] = 3 is assigned to group 1.",
|
| 33 |
+
"elements[0] = 5 is assigned to group 2.",
|
| 34 |
+
"Groups 0 and 3 cannot be assigned any element.",
|
| 35 |
+
"1 <= groups.length <= 105",
|
| 36 |
+
"1 <= elements.length <= 105",
|
| 37 |
+
"1 <= groups[i] <= 105",
|
| 38 |
+
"1 <= elements[i] <= 105"
|
| 39 |
+
],
|
| 40 |
+
"python_template": "class Solution(object):\n def assignElements(self, groups, elements):\n \"\"\"\n :type groups: List[int]\n :type elements: List[int]\n :rtype: List[int]\n \"\"\"\n ",
|
| 41 |
+
"java_template": "class Solution {\n public int[] assignElements(int[] groups, int[] elements) {\n \n }\n}",
|
| 42 |
+
"metadata": {
|
| 43 |
+
"func_name": "assignElements"
|
| 44 |
+
}
|
| 45 |
+
}
|
average-value-of-even-numbers-that-are-divisible-by-three.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2542,
|
| 3 |
+
"name": "average-value-of-even-numbers-that-are-divisible-by-three",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/",
|
| 6 |
+
"date": "2022-10-23",
|
| 7 |
+
"task_description": "Given an integer array `nums` of **positive** integers, return _the average value of all even integers that are divisible by_ `3`. Note that the **average** of `n` elements is the **sum** of the `n` elements divided by `n` and **rounded down** to the nearest integer. **Example 1:** ``` **Input:** nums = [1,3,6,10,12,15] **Output:** 9 **Explanation:** 6 and 12 are even numbers that are divisible by 3. (6 + 12) / 2 = 9. ``` **Example 2:** ``` **Input:** nums = [1,2,4,7,10] **Output:** 0 **Explanation:** There is no single number that satisfies the requirement, so return 0. ``` **Constraints:** `1 <= nums.length <= 1000` `1 <= nums[i] <= 1000`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [1,3,6,10,12,15]",
|
| 12 |
+
"output": "9 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [1,2,4,7,10]",
|
| 17 |
+
"output": "0 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"1 <= nums.length <= 1000",
|
| 22 |
+
"1 <= nums[i] <= 1000"
|
| 23 |
+
],
|
| 24 |
+
"python_template": "class Solution(object):\n def averageValue(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
|
| 25 |
+
"java_template": "class Solution {\n public int averageValue(int[] nums) {\n \n }\n}",
|
| 26 |
+
"metadata": {
|
| 27 |
+
"func_name": "averageValue"
|
| 28 |
+
}
|
| 29 |
+
}
|
beautiful-towers-i.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3114,
|
| 3 |
+
"name": "beautiful-towers-i",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/beautiful-towers-i/",
|
| 6 |
+
"date": "2023-09-17",
|
| 7 |
+
"task_description": "You are given an array `heights` of `n` integers representing the number of bricks in `n` consecutive towers. Your task is to remove some bricks to form a **mountain-shaped** tower arrangement. In this arrangement, the tower heights are non-decreasing, reaching a maximum peak value with one or multiple consecutive towers and then non-increasing. Return the **maximum possible sum** of heights of a mountain-shaped tower arrangement. **Example 1:** **Input:** heights = [5,3,4,1,1] **Output:** 13 **Explanation:** We remove some bricks to make `heights = [5,3,3,1,1]`, the peak is at index 0. **Example 2:** **Input:** heights = [6,5,3,9,2,7] **Output:** 22 **Explanation:** We remove some bricks to make `heights = [3,3,3,9,2,2]`, the peak is at index 3. **Example 3:** **Input:** heights = [3,2,5,5,2,3] **Output:** 18 **Explanation:** We remove some bricks to make `heights = [2,2,5,5,2,2]`, the peak is at index 2 or 3. **Constraints:** `1 <= n == heights.length <= 103` `1 <= heights[i] <= 109`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "heights = [5,3,4,1,1]",
|
| 12 |
+
"output": "13 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "heights = [6,5,3,9,2,7]",
|
| 17 |
+
"output": "22 "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "heights = [3,2,5,5,2,3]",
|
| 22 |
+
"output": "18 "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"1 <= n == heights.length <= 103",
|
| 27 |
+
"1 <= heights[i] <= 109"
|
| 28 |
+
],
|
| 29 |
+
"python_template": "class Solution(object):\n def maximumSumOfHeights(self, heights):\n \"\"\"\n :type heights: List[int]\n :rtype: int\n \"\"\"\n ",
|
| 30 |
+
"java_template": "class Solution {\n public long maximumSumOfHeights(int[] heights) {\n \n }\n}",
|
| 31 |
+
"metadata": {
|
| 32 |
+
"func_name": "maximumSumOfHeights"
|
| 33 |
+
}
|
| 34 |
+
}
|
beautiful-towers-ii.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3113,
|
| 3 |
+
"name": "beautiful-towers-ii",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/beautiful-towers-ii/",
|
| 6 |
+
"date": "2023-09-17",
|
| 7 |
+
"task_description": "You are given a **0-indexed** array `maxHeights` of `n` integers. You are tasked with building `n` towers in the coordinate line. The `ith` tower is built at coordinate `i` and has a height of `heights[i]`. A configuration of towers is **beautiful** if the following conditions hold: `1 <= heights[i] <= maxHeights[i]` `heights` is a **mountain** array. Array `heights` is a **mountain** if there exists an index `i` such that: For all `0 < j <= i`, `heights[j - 1] <= heights[j]` For all `i <= k < n - 1`, `heights[k + 1] <= heights[k]` Return _the **maximum possible sum of heights** of a beautiful configuration of towers_. **Example 1:** ``` **Input:** maxHeights = [5,3,4,1,1] **Output:** 13 **Explanation:** One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since: - 1 <= heights[i] <= maxHeights[i] - heights is a mountain of peak i = 0. It can be shown that there exists no other beautiful configuration with a sum of heights greater than 13. ``` **Example 2:** ``` **Input:** maxHeights = [6,5,3,9,2,7] **Output:** 22 **Explanation:** One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since: - 1 <= heights[i] <= maxHeights[i] - heights is a mountain of peak i = 3. It can be shown that there exists no other beautiful configuration with a sum of heights greater than 22. ``` **Example 3:** ``` **Input:** maxHeights = [3,2,5,5,2,3] **Output:** 18 **Explanation:** One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since: - 1 <= heights[i] <= maxHeights[i] - heights is a mountain of peak i = 2. Note that, for this configuration, i = 3 can also be considered a peak. It can be shown that there exists no other beautiful configuration with a sum of heights greater than 18. ``` **Constraints:** `1 <= n == maxHeights.length <= 105` `1 <= maxHeights[i] <= 109`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "maxHeights = [5,3,4,1,1]",
|
| 12 |
+
"output": "13 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "maxHeights = [6,5,3,9,2,7]",
|
| 17 |
+
"output": "22 "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "maxHeights = [3,2,5,5,2,3]",
|
| 22 |
+
"output": "18 "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"For all 0 < j <= i, heights[j - 1] <= heights[j]",
|
| 27 |
+
"For all i <= k < n - 1, heights[k + 1] <= heights[k]",
|
| 28 |
+
"1 <= n == maxHeights.length <= 105",
|
| 29 |
+
"1 <= maxHeights[i] <= 109"
|
| 30 |
+
],
|
| 31 |
+
"python_template": "class Solution(object):\n def maximumSumOfHeights(self, maxHeights):\n \"\"\"\n :type maxHeights: List[int]\n :rtype: int\n \"\"\"\n ",
|
| 32 |
+
"java_template": "class Solution {\n public long maximumSumOfHeights(List<Integer> maxHeights) {\n \n }\n}",
|
| 33 |
+
"metadata": {
|
| 34 |
+
"func_name": "maximumSumOfHeights"
|
| 35 |
+
}
|
| 36 |
+
}
|
best-poker-hand.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2433,
|
| 3 |
+
"name": "best-poker-hand",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/best-poker-hand/",
|
| 6 |
+
"date": "2022-07-09",
|
| 7 |
+
"task_description": "You are given an integer array `ranks` and a character array `suits`. You have `5` cards where the `ith` card has a rank of `ranks[i]` and a suit of `suits[i]`. The following are the types of **poker hands** you can make from best to worst: `\"Flush\"`: Five cards of the same suit. `\"Three of a Kind\"`: Three cards of the same rank. `\"Pair\"`: Two cards of the same rank. `\"High Card\"`: Any single card. Return _a string representing the **best** type of **poker hand** you can make with the given cards._ **Note** that the return values are **case-sensitive**. **Example 1:** ``` **Input:** ranks = [13,2,3,1,9], suits = [\"a\",\"a\",\"a\",\"a\",\"a\"] **Output:** \"Flush\" **Explanation:** The hand with all the cards consists of 5 cards with the same suit, so we have a \"Flush\". ``` **Example 2:** ``` **Input:** ranks = [4,4,2,4,4], suits = [\"d\",\"a\",\"a\",\"b\",\"c\"] **Output:** \"Three of a Kind\" **Explanation:** The hand with the first, second, and fourth card consists of 3 cards with the same rank, so we have a \"Three of a Kind\". Note that we could also make a \"Pair\" hand but \"Three of a Kind\" is a better hand. Also note that other cards could be used to make the \"Three of a Kind\" hand. ``` **Example 3:** ``` **Input:** ranks = [10,10,2,12,9], suits = [\"a\",\"b\",\"c\",\"a\",\"d\"] **Output:** \"Pair\" **Explanation:** The hand with the first and second card consists of 2 cards with the same rank, so we have a \"Pair\". Note that we cannot make a \"Flush\" or a \"Three of a Kind\". ``` **Constraints:** `ranks.length == suits.length == 5` `1 <= ranks[i] <= 13` `'a' <= suits[i] <= 'd'` No two cards have the same rank and suit.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "ranks = [13,2,3,1,9], suits = [\"a\",\"a\",\"a\",\"a\",\"a\"]",
|
| 12 |
+
"output": "\"Flush\" "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "ranks = [4,4,2,4,4], suits = [\"d\",\"a\",\"a\",\"b\",\"c\"]",
|
| 17 |
+
"output": "\"Three of a Kind\" "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "ranks = [10,10,2,12,9], suits = [\"a\",\"b\",\"c\",\"a\",\"d\"]",
|
| 22 |
+
"output": "\"Pair\" "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"ranks.length == suits.length == 5",
|
| 27 |
+
"1 <= ranks[i] <= 13",
|
| 28 |
+
"'a' <= suits[i] <= 'd'",
|
| 29 |
+
"No two cards have the same rank and suit."
|
| 30 |
+
],
|
| 31 |
+
"python_template": "class Solution(object):\n def bestHand(self, ranks, suits):\n \"\"\"\n :type ranks: List[int]\n :type suits: List[str]\n :rtype: str\n \"\"\"\n ",
|
| 32 |
+
"java_template": "class Solution {\n public String bestHand(int[] ranks, char[] suits) {\n \n }\n}",
|
| 33 |
+
"metadata": {
|
| 34 |
+
"func_name": "bestHand"
|
| 35 |
+
}
|
| 36 |
+
}
|
bitwise-xor-of-all-pairings.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2533,
|
| 3 |
+
"name": "bitwise-xor-of-all-pairings",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/bitwise-xor-of-all-pairings/",
|
| 6 |
+
"date": "2022-09-17",
|
| 7 |
+
"task_description": "You are given two **0-indexed** arrays, `nums1` and `nums2`, consisting of non-negative integers. Let there be another array, `nums3`, which contains the bitwise XOR of **all pairings** of integers between `nums1` and `nums2` (every integer in `nums1` is paired with every integer in `nums2` **exactly once**). Return_ the **bitwise XOR** of all integers in _`nums3`. **Example 1:** ``` **Input:** nums1 = [2,1,3], nums2 = [10,2,5,0] **Output:** 13 **Explanation:** A possible nums3 array is [8,0,7,2,11,3,4,1,9,1,6,3]. The bitwise XOR of all these numbers is 13, so we return 13. ``` **Example 2:** ``` **Input:** nums1 = [1,2], nums2 = [3,4] **Output:** 0 **Explanation:** All possible pairs of bitwise XORs are nums1[0] ^ nums2[0], nums1[0] ^ nums2[1], nums1[1] ^ nums2[0], and nums1[1] ^ nums2[1]. Thus, one possible nums3 array is [2,5,1,6]. 2 ^ 5 ^ 1 ^ 6 = 0, so we return 0. ``` **Constraints:** `1 <= nums1.length, nums2.length <= 105` `0 <= nums1[i], nums2[j] <= 109`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums1 = [2,1,3], nums2 = [10,2,5,0]",
|
| 12 |
+
"output": "13 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums1 = [1,2], nums2 = [3,4]",
|
| 17 |
+
"output": "0 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"1 <= nums1.length, nums2.length <= 105",
|
| 22 |
+
"0 <= nums1[i], nums2[j] <= 109"
|
| 23 |
+
],
|
| 24 |
+
"python_template": "class Solution(object):\n def xorAllNums(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"\n ",
|
| 25 |
+
"java_template": "class Solution {\n public int xorAllNums(int[] nums1, int[] nums2) {\n \n }\n}",
|
| 26 |
+
"metadata": {
|
| 27 |
+
"func_name": "xorAllNums"
|
| 28 |
+
}
|
| 29 |
+
}
|
buy-two-chocolates.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2756,
|
| 3 |
+
"name": "buy-two-chocolates",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/buy-two-chocolates/",
|
| 6 |
+
"date": "2023-05-13",
|
| 7 |
+
"task_description": "You are given an integer array `prices` representing the prices of various chocolates in a store. You are also given a single integer `money`, which represents your initial amount of money. You must buy **exactly** two chocolates in such a way that you still have some **non-negative** leftover money. You would like to minimize the sum of the prices of the two chocolates you buy. Return _the amount of money you will have leftover after buying the two chocolates_. If there is no way for you to buy two chocolates without ending up in debt, return `money`. Note that the leftover must be non-negative. **Example 1:** ``` **Input:** prices = [1,2,2], money = 3 **Output:** 0 **Explanation:** Purchase the chocolates priced at 1 and 2 units respectively. You will have 3 - 3 = 0 units of money afterwards. Thus, we return 0. ``` **Example 2:** ``` **Input:** prices = [3,2,3], money = 3 **Output:** 3 **Explanation:** You cannot buy 2 chocolates without going in debt, so we return 3. ``` **Constraints:** `2 <= prices.length <= 50` `1 <= prices[i] <= 100` `1 <= money <= 100`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "prices = [1,2,2], money = 3",
|
| 12 |
+
"output": "0 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "prices = [3,2,3], money = 3",
|
| 17 |
+
"output": "3 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"2 <= prices.length <= 50",
|
| 22 |
+
"1 <= prices[i] <= 100",
|
| 23 |
+
"1 <= money <= 100"
|
| 24 |
+
],
|
| 25 |
+
"python_template": "class Solution(object):\n def buyChoco(self, prices, money):\n \"\"\"\n :type prices: List[int]\n :type money: int\n :rtype: int\n \"\"\"\n ",
|
| 26 |
+
"java_template": "class Solution {\n public int buyChoco(int[] prices, int money) {\n \n }\n}",
|
| 27 |
+
"metadata": {
|
| 28 |
+
"func_name": "buyChoco"
|
| 29 |
+
}
|
| 30 |
+
}
|
calculate-delayed-arrival-time.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2748,
|
| 3 |
+
"name": "calculate-delayed-arrival-time",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/calculate-delayed-arrival-time/",
|
| 6 |
+
"date": "2023-04-16",
|
| 7 |
+
"task_description": "You are given a positive integer `arrivalTime` denoting the arrival time of a train in hours, and another positive integer `delayedTime` denoting the amount of delay in hours. Return _the time when the train will arrive at the station._ Note that the time in this problem is in 24-hours format. **Example 1:** ``` **Input:** arrivalTime = 15, delayedTime = 5 **Output:** 20 **Explanation:** Arrival time of the train was 15:00 hours. It is delayed by 5 hours. Now it will reach at 15+5 = 20 (20:00 hours). ``` **Example 2:** ``` **Input:** arrivalTime = 13, delayedTime = 11 **Output:** 0 **Explanation:** Arrival time of the train was 13:00 hours. It is delayed by 11 hours. Now it will reach at 13+11=24 (Which is denoted by 00:00 in 24 hours format so return 0). ``` **Constraints:** `1 <= arrivaltime < 24` `1 <= delayedTime <= 24`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "arrivalTime = 15, delayedTime = 5",
|
| 12 |
+
"output": "20 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "arrivalTime = 13, delayedTime = 11",
|
| 17 |
+
"output": "0 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"1 <= arrivaltime < 24",
|
| 22 |
+
"1 <= delayedTime <= 24"
|
| 23 |
+
],
|
| 24 |
+
"python_template": "class Solution(object):\n def findDelayedArrivalTime(self, arrivalTime, delayedTime):\n \"\"\"\n :type arrivalTime: int\n :type delayedTime: int\n :rtype: int\n \"\"\"\n ",
|
| 25 |
+
"java_template": "class Solution {\n public int findDelayedArrivalTime(int arrivalTime, int delayedTime) {\n \n }\n}",
|
| 26 |
+
"metadata": {
|
| 27 |
+
"func_name": "findDelayedArrivalTime"
|
| 28 |
+
}
|
| 29 |
+
}
|
calculate-digit-sum-of-a-string.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2361,
|
| 3 |
+
"name": "calculate-digit-sum-of-a-string",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/calculate-digit-sum-of-a-string/",
|
| 6 |
+
"date": "2022-04-10",
|
| 7 |
+
"task_description": "You are given a string `s` consisting of digits and an integer `k`. A **round** can be completed if the length of `s` is greater than `k`. In one round, do the following: **Divide** `s` into **consecutive groups** of size `k` such that the first `k` characters are in the first group, the next `k` characters are in the second group, and so on. **Note** that the size of the last group can be smaller than `k`. **Replace** each group of `s` with a string representing the sum of all its digits. For example, `\"346\"` is replaced with `\"13\"` because `3 + 4 + 6 = 13`. **Merge** consecutive groups together to form a new string. If the length of the string is greater than `k`, repeat from step `1`. Return `s` _after all rounds have been completed_. **Example 1:** ``` **Input:** s = \"11111222223\", k = 3 **Output:** \"135\" **Explanation:** - For the first round, we divide s into groups of size 3: \"111\", \"112\", \"222\", and \"23\". Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5. So, s becomes \"3\" + \"4\" + \"6\" + \"5\" = \"3465\" after the first round. - For the second round, we divide s into \"346\" and \"5\". Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5. So, s becomes \"13\" + \"5\" = \"135\" after second round. Now, s.length <= k, so we return \"135\" as the answer. ``` **Example 2:** ``` **Input:** s = \"00000000\", k = 3 **Output:** \"000\" **Explanation:** We divide s into \"000\", \"000\", and \"00\". Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0. s becomes \"0\" + \"0\" + \"0\" = \"000\", whose length is equal to k, so we return \"000\". ``` **Constraints:** `1 <= s.length <= 100` `2 <= k <= 100` `s` consists of digits only.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"11111222223\", k = 3",
|
| 12 |
+
"output": "\"135\" "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"00000000\", k = 3",
|
| 17 |
+
"output": "\"000\" "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"1 <= s.length <= 100",
|
| 22 |
+
"2 <= k <= 100",
|
| 23 |
+
"s consists of digits only."
|
| 24 |
+
],
|
| 25 |
+
"python_template": "class Solution(object):\n def digitSum(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"\n ",
|
| 26 |
+
"java_template": "class Solution {\n public String digitSum(String s, int k) {\n \n }\n}",
|
| 27 |
+
"metadata": {
|
| 28 |
+
"func_name": "digitSum"
|
| 29 |
+
}
|
| 30 |
+
}
|
categorize-box-according-to-criteria.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2619,
|
| 3 |
+
"name": "categorize-box-according-to-criteria",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/categorize-box-according-to-criteria/",
|
| 6 |
+
"date": "2022-12-24",
|
| 7 |
+
"task_description": "Given four integers `length`, `width`, `height`, and `mass`, representing the dimensions and mass of a box, respectively, return _a string representing the **category** of the box_. The box is `\"Bulky\"` if: **Any** of the dimensions of the box is greater or equal to `104`. Or, the **volume** of the box is greater or equal to `109`. If the mass of the box is greater or equal to `100`, it is `\"Heavy\".` If the box is both `\"Bulky\"` and `\"Heavy\"`, then its category is `\"Both\"`. If the box is neither `\"Bulky\"` nor `\"Heavy\"`, then its category is `\"Neither\"`. If the box is `\"Bulky\"` but not `\"Heavy\"`, then its category is `\"Bulky\"`. If the box is `\"Heavy\"` but not `\"Bulky\"`, then its category is `\"Heavy\"`. **Note** that the volume of the box is the product of its length, width and height. **Example 1:** ``` **Input:** length = 1000, width = 35, height = 700, mass = 300 **Output:** \"Heavy\" **Explanation:** None of the dimensions of the box is greater or equal to 104. Its volume = 24500000 <= 109. So it cannot be categorized as \"Bulky\". However mass >= 100, so the box is \"Heavy\". Since the box is not \"Bulky\" but \"Heavy\", we return \"Heavy\". ``` **Example 2:** ``` **Input:** length = 200, width = 50, height = 800, mass = 50 **Output:** \"Neither\" **Explanation:** None of the dimensions of the box is greater or equal to 104. Its volume = 8 * 106 <= 109. So it cannot be categorized as \"Bulky\". Its mass is also less than 100, so it cannot be categorized as \"Heavy\" either. Since its neither of the two above categories, we return \"Neither\". ``` **Constraints:** `1 <= length, width, height <= 105` `1 <= mass <= 103`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "length = 1000, width = 35, height = 700, mass = 300",
|
| 12 |
+
"output": "\"Heavy\" "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "length = 200, width = 50, height = 800, mass = 50",
|
| 17 |
+
"output": "\"Neither\" "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"The box is \"Bulky\" if:\n\n\t\nAny of the dimensions of the box is greater or equal to 104.\nOr, the volume of the box is greater or equal to 109.",
|
| 22 |
+
"Any of the dimensions of the box is greater or equal to 104.",
|
| 23 |
+
"Or, the volume of the box is greater or equal to 109.",
|
| 24 |
+
"If the mass of the box is greater or equal to 100, it is \"Heavy\".",
|
| 25 |
+
"If the box is both \"Bulky\" and \"Heavy\", then its category is \"Both\".",
|
| 26 |
+
"If the box is neither \"Bulky\" nor \"Heavy\", then its category is \"Neither\".",
|
| 27 |
+
"If the box is \"Bulky\" but not \"Heavy\", then its category is \"Bulky\".",
|
| 28 |
+
"If the box is \"Heavy\" but not \"Bulky\", then its category is \"Heavy\".",
|
| 29 |
+
"Any of the dimensions of the box is greater or equal to 104.",
|
| 30 |
+
"Or, the volume of the box is greater or equal to 109.",
|
| 31 |
+
"1 <= length, width, height <= 105",
|
| 32 |
+
"1 <= mass <= 103"
|
| 33 |
+
],
|
| 34 |
+
"python_template": "class Solution(object):\n def categorizeBox(self, length, width, height, mass):\n \"\"\"\n :type length: int\n :type width: int\n :type height: int\n :type mass: int\n :rtype: str\n \"\"\"\n ",
|
| 35 |
+
"java_template": "class Solution {\n public String categorizeBox(int length, int width, int height, int mass) {\n \n }\n}",
|
| 36 |
+
"metadata": {
|
| 37 |
+
"func_name": "categorizeBox"
|
| 38 |
+
}
|
| 39 |
+
}
|
cells-in-a-range-on-an-excel-sheet.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2304,
|
| 3 |
+
"name": "cells-in-a-range-on-an-excel-sheet",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/",
|
| 6 |
+
"date": "2022-02-27",
|
| 7 |
+
"task_description": "A cell `(r, c)` of an excel sheet is represented as a string `\"<col><row>\"` where: `<col>` denotes the column number `c` of the cell. It is represented by **alphabetical letters**. For example, the `1st` column is denoted by `'A'`, the `2nd` by `'B'`, the `3rd` by `'C'`, and so on. `<row>` is the row number `r` of the cell. The `rth` row is represented by the **integer** `r`. You are given a string `s` in the format `\"<col1><row1>:<col2><row2>\"`, where `<col1>` represents the column `c1`, `<row1>` represents the row `r1`, `<col2>` represents the column `c2`, and `<row2>` represents the row `r2`, such that `r1 <= r2` and `c1 <= c2`. Return _the **list of cells**_ `(x, y)` _such that_ `r1 <= x <= r2` _and_ `c1 <= y <= c2`. The cells should be represented as **strings** in the format mentioned above and be sorted in **non-decreasing** order first by columns and then by rows. **Example 1:** ``` **Input:** s = \"K1:L2\" **Output:** [\"K1\",\"K2\",\"L1\",\"L2\"] **Explanation:** The above diagram shows the cells which should be present in the list. The red arrows denote the order in which the cells should be presented. ``` **Example 2:** ``` **Input:** s = \"A1:F1\" **Output:** [\"A1\",\"B1\",\"C1\",\"D1\",\"E1\",\"F1\"] **Explanation:** The above diagram shows the cells which should be present in the list. The red arrow denotes the order in which the cells should be presented. ``` **Constraints:** `s.length == 5` `'A' <= s[0] <= s[3] <= 'Z'` `'1' <= s[1] <= s[4] <= '9'` `s` consists of uppercase English letters, digits and `':'`.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"K1:L2\"",
|
| 12 |
+
"output": "[\"K1\",\"K2\",\"L1\",\"L2\"] "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"A1:F1\"",
|
| 17 |
+
"output": "[\"A1\",\"B1\",\"C1\",\"D1\",\"E1\",\"F1\"] "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"<col> denotes the column number c of the cell. It is represented by alphabetical letters.\n\n\t\nFor example, the 1st column is denoted by 'A', the 2nd by 'B', the 3rd by 'C', and so on.",
|
| 22 |
+
"For example, the 1st column is denoted by 'A', the 2nd by 'B', the 3rd by 'C', and so on.",
|
| 23 |
+
"<row> is the row number r of the cell. The rth row is represented by the integer r.",
|
| 24 |
+
"For example, the 1st column is denoted by 'A', the 2nd by 'B', the 3rd by 'C', and so on.",
|
| 25 |
+
"s.length == 5",
|
| 26 |
+
"'A' <= s[0] <= s[3] <= 'Z'",
|
| 27 |
+
"'1' <= s[1] <= s[4] <= '9'",
|
| 28 |
+
"s consists of uppercase English letters, digits and ':'."
|
| 29 |
+
],
|
| 30 |
+
"python_template": "class Solution(object):\n def cellsInRange(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"\n ",
|
| 31 |
+
"java_template": "class Solution {\n public List<String> cellsInRange(String s) {\n \n }\n}",
|
| 32 |
+
"metadata": {
|
| 33 |
+
"func_name": "cellsInRange"
|
| 34 |
+
}
|
| 35 |
+
}
|
check-distances-between-same-letters.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2476,
|
| 3 |
+
"name": "check-distances-between-same-letters",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-distances-between-same-letters/",
|
| 6 |
+
"date": "2022-08-28",
|
| 7 |
+
"task_description": "You are given a **0-indexed** string `s` consisting of only lowercase English letters, where each letter in `s` appears **exactly** **twice**. You are also given a **0-indexed** integer array `distance` of length `26`. Each letter in the alphabet is numbered from `0` to `25` (i.e. `'a' -> 0`, `'b' -> 1`, `'c' -> 2`, ... , `'z' -> 25`). In a **well-spaced** string, the number of letters between the two occurrences of the `ith` letter is `distance[i]`. If the `ith` letter does not appear in `s`, then `distance[i]` can be **ignored**. Return `true`_ if _`s`_ is a **well-spaced** string, otherwise return _`false`. **Example 1:** ``` **Input:** s = \"abaccb\", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] **Output:** true **Explanation:** - 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1. - 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3. - 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0. Note that distance[3] = 5, but since 'd' does not appear in s, it can be ignored. Return true because s is a well-spaced string. ``` **Example 2:** ``` **Input:** s = \"aa\", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] **Output:** false **Explanation:** - 'a' appears at indices 0 and 1 so there are zero letters between them. Because distance[0] = 1, s is not a well-spaced string. ``` **Constraints:** `2 <= s.length <= 52` `s` consists only of lowercase English letters. Each letter appears in `s` exactly twice. `distance.length == 26` `0 <= distance[i] <= 50`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"abaccb\", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"aa\", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"2 <= s.length <= 52",
|
| 22 |
+
"s consists only of lowercase English letters.",
|
| 23 |
+
"Each letter appears in s exactly twice.",
|
| 24 |
+
"distance.length == 26",
|
| 25 |
+
"0 <= distance[i] <= 50"
|
| 26 |
+
],
|
| 27 |
+
"python_template": "class Solution(object):\n def checkDistances(self, s, distance):\n \"\"\"\n :type s: str\n :type distance: List[int]\n :rtype: bool\n \"\"\"\n ",
|
| 28 |
+
"java_template": "class Solution {\n public boolean checkDistances(String s, int[] distance) {\n \n }\n}",
|
| 29 |
+
"metadata": {
|
| 30 |
+
"func_name": "checkDistances"
|
| 31 |
+
}
|
| 32 |
+
}
|
check-if-array-is-good.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2892,
|
| 3 |
+
"name": "check-if-array-is-good",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-array-is-good/",
|
| 6 |
+
"date": "2023-07-08",
|
| 7 |
+
"task_description": "You are given an integer array `nums`. We consider an array **good **if it is a permutation of an array `base[n]`. `base[n] = [1, 2, ..., n - 1, n, n] `(in other words, it is an array of length `n + 1` which contains `1` to `n - 1 `exactly once, plus two occurrences of `n`). For example, `base[1] = [1, 1]` and` base[3] = [1, 2, 3, 3]`. Return `true` _if the given array is good, otherwise return__ _`false`. **Note: **A permutation of integers represents an arrangement of these numbers. **Example 1:** ``` **Input:** nums = [2, 1, 3] **Output:** false **Explanation:** Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false. ``` **Example 2:** ``` **Input:** nums = [1, 3, 3, 2] **Output:** true **Explanation:** Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true. ``` **Example 3:** ``` **Input:** nums = [1, 1] **Output:** true **Explanation:** Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true. ``` **Example 4:** ``` **Input:** nums = [3, 4, 4, 1, 2, 1] **Output:** false **Explanation:** Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false. ``` **Constraints:** `1 <= nums.length <= 100` `1 <= num[i] <= 200`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [2, 1, 3]",
|
| 12 |
+
"output": "false "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [1, 3, 3, 2]",
|
| 17 |
+
"output": "true "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "nums = [1, 1]",
|
| 22 |
+
"output": "true "
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"label": "Example 4",
|
| 26 |
+
"input": "nums = [3, 4, 4, 1, 2, 1]",
|
| 27 |
+
"output": "false "
|
| 28 |
+
}
|
| 29 |
+
],
|
| 30 |
+
"constraints": [
|
| 31 |
+
"1 <= nums.length <= 100",
|
| 32 |
+
"1 <= num[i] <= 200"
|
| 33 |
+
],
|
| 34 |
+
"python_template": "class Solution(object):\n def isGood(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n ",
|
| 35 |
+
"java_template": "class Solution {\n public boolean isGood(int[] nums) {\n \n }\n}",
|
| 36 |
+
"metadata": {
|
| 37 |
+
"func_name": "isGood"
|
| 38 |
+
}
|
| 39 |
+
}
|
check-if-bitwise-or-has-trailing-zeros.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3246,
|
| 3 |
+
"name": "check-if-bitwise-or-has-trailing-zeros",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros/",
|
| 6 |
+
"date": "2023-12-24",
|
| 7 |
+
"task_description": "You are given an array of **positive** integers `nums`. You have to check if it is possible to select **two or more** elements in the array such that the bitwise `OR` of the selected elements has **at least **one trailing zero in its binary representation. For example, the binary representation of `5`, which is `\"101\"`, does not have any trailing zeros, whereas the binary representation of `4`, which is `\"100\"`, has two trailing zeros. Return `true` _if it is possible to select two or more elements whose bitwise_ `OR` _has trailing zeros, return_ `false` _otherwise_. **Example 1:** ``` **Input:** nums = [1,2,3,4,5] **Output:** true **Explanation:** If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero. ``` **Example 2:** ``` **Input:** nums = [2,4,8,16] **Output:** true **Explanation: **If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero. Other possible ways to select elements to have trailing zeroes in the binary representation of their bitwise OR are: (2, 8), (2, 16), (4, 8), (4, 16), (8, 16), (2, 4, 8), (2, 4, 16), (2, 8, 16), (4, 8, 16), and (2, 4, 8, 16). ``` **Example 3:** ``` **Input:** nums = [1,3,5,7,9] **Output:** false **Explanation:** There is no possible way to select two or more elements to have trailing zeros in the binary representation of their bitwise OR. ``` **Constraints:** `2 <= nums.length <= 100` `1 <= nums[i] <= 100`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [1,2,3,4,5]",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [2,4,8,16]",
|
| 17 |
+
"output": "true "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "nums = [1,3,5,7,9]",
|
| 22 |
+
"output": "false "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"2 <= nums.length <= 100",
|
| 27 |
+
"1 <= nums[i] <= 100"
|
| 28 |
+
],
|
| 29 |
+
"python_template": "class Solution(object):\n def hasTrailingZeros(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n ",
|
| 30 |
+
"java_template": "class Solution {\n public boolean hasTrailingZeros(int[] nums) {\n \n }\n}",
|
| 31 |
+
"metadata": {
|
| 32 |
+
"func_name": "hasTrailingZeros"
|
| 33 |
+
}
|
| 34 |
+
}
|
check-if-digits-are-equal-in-string-after-operations-i.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3768,
|
| 3 |
+
"name": "check-if-digits-are-equal-in-string-after-operations-i",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-digits-are-equal-in-string-after-operations-i/",
|
| 6 |
+
"date": "2025-02-16",
|
| 7 |
+
"task_description": "You are given a string `s` consisting of digits. Perform the following operation repeatedly until the string has **exactly** two digits: For each pair of consecutive digits in `s`, starting from the first digit, calculate a new digit as the sum of the two digits **modulo** 10. Replace `s` with the sequence of newly calculated digits, _maintaining the order_ in which they are computed. Return `true` if the final two digits in `s` are the **same**; otherwise, return `false`. **Example 1:** **Input:** s = \"3902\" **Output:** true **Explanation:** Initially, `s = \"3902\"` First operation: `(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2` `(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9` `(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2` `s` becomes `\"292\"` Second operation: `(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1` `(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1` `s` becomes `\"11\"` Since the digits in `\"11\"` are the same, the output is `true`. **Example 2:** **Input:** s = \"34789\" **Output:** false **Explanation:** Initially, `s = \"34789\"`. After the first operation, `s = \"7157\"`. After the second operation, `s = \"862\"`. After the third operation, `s = \"48\"`. Since `'4' != '8'`, the output is `false`. **Constraints:** `3 <= s.length <= 100` `s` consists of only digits.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"3902\"",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"34789\"",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10.",
|
| 22 |
+
"Replace s with the sequence of newly calculated digits, maintaining the order in which they are computed.",
|
| 23 |
+
"Initially, s = \"3902\"",
|
| 24 |
+
"First operation:\n\t\n(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2\n(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9\n(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2\ns becomes \"292\"",
|
| 25 |
+
"(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2",
|
| 26 |
+
"(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9",
|
| 27 |
+
"(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2",
|
| 28 |
+
"s becomes \"292\"",
|
| 29 |
+
"Second operation:\n\t\n(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1\n(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1\ns becomes \"11\"",
|
| 30 |
+
"(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1",
|
| 31 |
+
"(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1",
|
| 32 |
+
"s becomes \"11\"",
|
| 33 |
+
"Since the digits in \"11\" are the same, the output is true.",
|
| 34 |
+
"(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2",
|
| 35 |
+
"(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9",
|
| 36 |
+
"(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2",
|
| 37 |
+
"s becomes \"292\"",
|
| 38 |
+
"(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1",
|
| 39 |
+
"(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1",
|
| 40 |
+
"s becomes \"11\"",
|
| 41 |
+
"Initially, s = \"34789\".",
|
| 42 |
+
"After the first operation, s = \"7157\".",
|
| 43 |
+
"After the second operation, s = \"862\".",
|
| 44 |
+
"After the third operation, s = \"48\".",
|
| 45 |
+
"Since '4' != '8', the output is false.",
|
| 46 |
+
"3 <= s.length <= 100",
|
| 47 |
+
"s consists of only digits."
|
| 48 |
+
],
|
| 49 |
+
"python_template": "class Solution(object):\n def hasSameDigits(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"\n ",
|
| 50 |
+
"java_template": "class Solution {\n public boolean hasSameDigits(String s) {\n \n }\n}",
|
| 51 |
+
"metadata": {
|
| 52 |
+
"func_name": "hasSameDigits"
|
| 53 |
+
}
|
| 54 |
+
}
|
check-if-digits-are-equal-in-string-after-operations-ii.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3774,
|
| 3 |
+
"name": "check-if-digits-are-equal-in-string-after-operations-ii",
|
| 4 |
+
"difficulty": "Hard",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-digits-are-equal-in-string-after-operations-ii/",
|
| 6 |
+
"date": "2025-02-16",
|
| 7 |
+
"task_description": "You are given a string `s` consisting of digits. Perform the following operation repeatedly until the string has **exactly** two digits: For each pair of consecutive digits in `s`, starting from the first digit, calculate a new digit as the sum of the two digits **modulo** 10. Replace `s` with the sequence of newly calculated digits, _maintaining the order_ in which they are computed. Return `true` if the final two digits in `s` are the **same**; otherwise, return `false`. **Example 1:** **Input:** s = \"3902\" **Output:** true **Explanation:** Initially, `s = \"3902\"` First operation: `(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2` `(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9` `(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2` `s` becomes `\"292\"` Second operation: `(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1` `(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1` `s` becomes `\"11\"` Since the digits in `\"11\"` are the same, the output is `true`. **Example 2:** **Input:** s = \"34789\" **Output:** false **Explanation:** Initially, `s = \"34789\"`. After the first operation, `s = \"7157\"`. After the second operation, `s = \"862\"`. After the third operation, `s = \"48\"`. Since `'4' != '8'`, the output is `false`. **Constraints:** `3 <= s.length <= 105` `s` consists of only digits.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"3902\"",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"34789\"",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10.",
|
| 22 |
+
"Replace s with the sequence of newly calculated digits, maintaining the order in which they are computed.",
|
| 23 |
+
"Initially, s = \"3902\"",
|
| 24 |
+
"First operation:\n\t\n(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2\n(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9\n(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2\ns becomes \"292\"",
|
| 25 |
+
"(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2",
|
| 26 |
+
"(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9",
|
| 27 |
+
"(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2",
|
| 28 |
+
"s becomes \"292\"",
|
| 29 |
+
"Second operation:\n\t\n(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1\n(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1\ns becomes \"11\"",
|
| 30 |
+
"(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1",
|
| 31 |
+
"(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1",
|
| 32 |
+
"s becomes \"11\"",
|
| 33 |
+
"Since the digits in \"11\" are the same, the output is true.",
|
| 34 |
+
"(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2",
|
| 35 |
+
"(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9",
|
| 36 |
+
"(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2",
|
| 37 |
+
"s becomes \"292\"",
|
| 38 |
+
"(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1",
|
| 39 |
+
"(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1",
|
| 40 |
+
"s becomes \"11\"",
|
| 41 |
+
"Initially, s = \"34789\".",
|
| 42 |
+
"After the first operation, s = \"7157\".",
|
| 43 |
+
"After the second operation, s = \"862\".",
|
| 44 |
+
"After the third operation, s = \"48\".",
|
| 45 |
+
"Since '4' != '8', the output is false.",
|
| 46 |
+
"3 <= s.length <= 105",
|
| 47 |
+
"s consists of only digits."
|
| 48 |
+
],
|
| 49 |
+
"python_template": "class Solution(object):\n def hasSameDigits(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"\n ",
|
| 50 |
+
"java_template": "class Solution {\n public boolean hasSameDigits(String s) {\n \n }\n}",
|
| 51 |
+
"metadata": {
|
| 52 |
+
"func_name": "hasSameDigits"
|
| 53 |
+
}
|
| 54 |
+
}
|
check-if-every-row-and-column-contains-all-numbers.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2254,
|
| 3 |
+
"name": "check-if-every-row-and-column-contains-all-numbers",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers/",
|
| 6 |
+
"date": "2022-01-02",
|
| 7 |
+
"task_description": "An `n x n` matrix is **valid** if every row and every column contains **all** the integers from `1` to `n` (**inclusive**). Given an `n x n` integer matrix `matrix`, return `true` _if the matrix is **valid**._ Otherwise, return `false`. **Example 1:** ``` **Input:** matrix = [[1,2,3],[3,1,2],[2,3,1]] **Output:** true **Explanation:** In this case, n = 3, and every row and column contains the numbers 1, 2, and 3. Hence, we return true. ``` **Example 2:** ``` **Input:** matrix = [[1,1,1],[1,2,3],[1,2,3]] **Output:** false **Explanation:** In this case, n = 3, but the first row and the first column do not contain the numbers 2 or 3. Hence, we return false. ``` **Constraints:** `n == matrix.length == matrix[i].length` `1 <= n <= 100` `1 <= matrix[i][j] <= n`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "matrix = [[1,2,3],[3,1,2],[2,3,1]]",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "matrix = [[1,1,1],[1,2,3],[1,2,3]]",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"n == matrix.length == matrix[i].length",
|
| 22 |
+
"1 <= n <= 100",
|
| 23 |
+
"1 <= matrix[i][j] <= n"
|
| 24 |
+
],
|
| 25 |
+
"python_template": "class Solution(object):\n def checkValid(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: bool\n \"\"\"\n ",
|
| 26 |
+
"java_template": "class Solution {\n public boolean checkValid(int[][] matrix) {\n \n }\n}",
|
| 27 |
+
"metadata": {
|
| 28 |
+
"func_name": "checkValid"
|
| 29 |
+
}
|
| 30 |
+
}
|
check-if-grid-can-be-cut-into-sections.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3657,
|
| 3 |
+
"name": "check-if-grid-can-be-cut-into-sections",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-grid-can-be-cut-into-sections/",
|
| 6 |
+
"date": "2024-12-07",
|
| 7 |
+
"task_description": "You are given an integer `n` representing the dimensions of an `n x n` grid, with the origin at the bottom-left corner of the grid. You are also given a 2D array of coordinates `rectangles`, where `rectangles[i]` is in the form `[startx, starty, endx, endy]`, representing a rectangle on the grid. Each rectangle is defined as follows: `(startx, starty)`: The bottom-left corner of the rectangle. `(endx, endy)`: The top-right corner of the rectangle. **Note **that the rectangles do not overlap. Your task is to determine if it is possible to make **either two horizontal or two vertical cuts** on the grid such that: Each of the three resulting sections formed by the cuts contains **at least** one rectangle. Every rectangle belongs to **exactly** one section. Return `true` if such cuts can be made; otherwise, return `false`. **Example 1:** **Input:** n = 5, rectangles = [[1,0,5,2],[0,2,2,4],[3,2,5,3],[0,4,4,5]] **Output:** true **Explanation:** The grid is shown in the diagram. We can make horizontal cuts at `y = 2` and `y = 4`. Hence, output is true. **Example 2:** **Input:** n = 4, rectangles = [[0,0,1,1],[2,0,3,4],[0,2,2,3],[3,0,4,3]] **Output:** true **Explanation:** We can make vertical cuts at `x = 2` and `x = 3`. Hence, output is true. **Example 3:** **Input:** n = 4, rectangles = [[0,2,2,4],[1,0,3,2],[2,2,3,4],[3,0,4,2],[3,2,4,4]] **Output:** false **Explanation:** We cannot make two horizontal or two vertical cuts that satisfy the conditions. Hence, output is false. **Constraints:** `3 <= n <= 109` `3 <= rectangles.length <= 105` `0 <= rectangles[i][0] < rectangles[i][2] <= n` `0 <= rectangles[i][1] < rectangles[i][3] <= n` No two rectangles overlap.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "n = 5, rectangles = [[1,0,5,2],[0,2,2,4],[3,2,5,3],[0,4,4,5]]",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "n = 4, rectangles = [[0,0,1,1],[2,0,3,4],[0,2,2,3],[3,0,4,3]]",
|
| 17 |
+
"output": "true "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "n = 4, rectangles = [[0,2,2,4],[1,0,3,2],[2,2,3,4],[3,0,4,2],[3,2,4,4]]",
|
| 22 |
+
"output": "false "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"(startx, starty): The bottom-left corner of the rectangle.",
|
| 27 |
+
"(endx, endy): The top-right corner of the rectangle.",
|
| 28 |
+
"Each of the three resulting sections formed by the cuts contains at least one rectangle.",
|
| 29 |
+
"Every rectangle belongs to exactly one section.",
|
| 30 |
+
"3 <= n <= 109",
|
| 31 |
+
"3 <= rectangles.length <= 105",
|
| 32 |
+
"0 <= rectangles[i][0] < rectangles[i][2] <= n",
|
| 33 |
+
"0 <= rectangles[i][1] < rectangles[i][3] <= n",
|
| 34 |
+
"No two rectangles overlap."
|
| 35 |
+
],
|
| 36 |
+
"python_template": "class Solution(object):\n def checkValidCuts(self, n, rectangles):\n \"\"\"\n :type n: int\n :type rectangles: List[List[int]]\n :rtype: bool\n \"\"\"\n ",
|
| 37 |
+
"java_template": "class Solution {\n public boolean checkValidCuts(int n, int[][] rectangles) {\n \n }\n}",
|
| 38 |
+
"metadata": {
|
| 39 |
+
"func_name": "checkValidCuts"
|
| 40 |
+
}
|
| 41 |
+
}
|
check-if-grid-satisfies-conditions.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3415,
|
| 3 |
+
"name": "check-if-grid-satisfies-conditions",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-grid-satisfies-conditions/",
|
| 6 |
+
"date": "2024-04-27",
|
| 7 |
+
"task_description": "You are given a 2D matrix `grid` of size `m x n`. You need to check if each cell `grid[i][j]` is: Equal to the cell below it, i.e. `grid[i][j] == grid[i + 1][j]` (if it exists). Different from the cell to its right, i.e. `grid[i][j] != grid[i][j + 1]` (if it exists). Return `true` if **all** the cells satisfy these conditions, otherwise, return `false`. **Example 1:** **Input:** grid = [[1,0,2],[1,0,2]] **Output:** true **Explanation:** **** All the cells in the grid satisfy the conditions. **Example 2:** **Input:** grid = [[1,1,1],[0,0,0]] **Output:** false **Explanation:** **** All cells in the first row are equal. **Example 3:** **Input:** grid = [[1],[2],[3]] **Output:** false **Explanation:** Cells in the first column have different values. **Constraints:** `1 <= n, m <= 10` `0 <= grid[i][j] <= 9`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "grid = [[1,0,2],[1,0,2]]",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "grid = [[1,1,1],[0,0,0]]",
|
| 17 |
+
"output": "false "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "grid = [[1],[2],[3]]",
|
| 22 |
+
"output": "false "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists).",
|
| 27 |
+
"Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists).",
|
| 28 |
+
"1 <= n, m <= 10",
|
| 29 |
+
"0 <= grid[i][j] <= 9"
|
| 30 |
+
],
|
| 31 |
+
"python_template": "class Solution(object):\n def satisfiesConditions(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: bool\n \"\"\"\n ",
|
| 32 |
+
"java_template": "class Solution {\n public boolean satisfiesConditions(int[][] grid) {\n \n }\n}",
|
| 33 |
+
"metadata": {
|
| 34 |
+
"func_name": "satisfiesConditions"
|
| 35 |
+
}
|
| 36 |
+
}
|
check-if-it-is-possible-to-split-array.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2916,
|
| 3 |
+
"name": "check-if-it-is-possible-to-split-array",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-it-is-possible-to-split-array/",
|
| 6 |
+
"date": "2023-07-30",
|
| 7 |
+
"task_description": "You are given an array `nums` of length `n` and an integer `m`. You need to determine if it is possible to split the array into `n` arrays of size 1 by performing a series of steps. An array is called **good** if: The length of the array is **one**, or The sum of the elements of the array is **greater than or equal** to `m`. In each step, you can select an existing array (which may be the result of previous steps) with a length of **at least two** and split it into **two **arrays, if both resulting arrays are good. Return true if you can split the given array into `n` arrays, otherwise return false. **Example 1:** **Input:** nums = [2, 2, 1], m = 4 **Output:** true **Explanation:** Split `[2, 2, 1]` to `[2, 2]` and `[1]`. The array `[1]` has a length of one, and the array `[2, 2]` has the sum of its elements equal to `4 >= m`, so both are good arrays. Split `[2, 2]` to `[2]` and `[2]`. both arrays have the length of one, so both are good arrays. **Example 2:** **Input:** nums = [2, 1, 3], m = 5 **Output:** false **Explanation:** The first move has to be either of the following: Split `[2, 1, 3]` to `[2, 1]` and `[3]`. The array `[2, 1]` has neither length of one nor sum of elements greater than or equal to `m`. Split `[2, 1, 3]` to `[2]` and `[1, 3]`. The array `[1, 3]` has neither length of one nor sum of elements greater than or equal to `m`. So as both moves are invalid (they do not divide the array into two good arrays), we are unable to split `nums` into `n` arrays of size 1. **Example 3:** **Input:** nums = [2, 3, 3, 2, 3], m = 6 **Output:** true **Explanation:** Split `[2, 3, 3, 2, 3]` to `[2]` and `[3, 3, 2, 3]`. Split `[3, 3, 2, 3]` to `[3, 3, 2]` and `[3]`. Split `[3, 3, 2]` to `[3, 3]` and `[2]`. Split `[3, 3]` to `[3]` and `[3]`. **Constraints:** `1 <= n == nums.length <= 100` `1 <= nums[i] <= 100` `1 <= m <= 200`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [2, 2, 1], m = 4",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [2, 1, 3], m = 5",
|
| 17 |
+
"output": "false "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "nums = [2, 3, 3, 2, 3], m = 6",
|
| 22 |
+
"output": "true "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"The length of the array is one, or",
|
| 27 |
+
"The sum of the elements of the array is greater than or equal to m.",
|
| 28 |
+
"Split [2, 2, 1] to [2, 2] and [1]. The array [1] has a length of one, and the array [2, 2] has the sum of its elements equal to 4 >= m, so both are good arrays.",
|
| 29 |
+
"Split [2, 2] to [2] and [2]. both arrays have the length of one, so both are good arrays.",
|
| 30 |
+
"Split [2, 1, 3] to [2, 1] and [3]. The array [2, 1] has neither length of one nor sum of elements greater than or equal to m.",
|
| 31 |
+
"Split [2, 1, 3] to [2] and [1, 3]. The array [1, 3] has neither length of one nor sum of elements greater than or equal to m.",
|
| 32 |
+
"Split [2, 3, 3, 2, 3] to [2] and [3, 3, 2, 3].",
|
| 33 |
+
"Split [3, 3, 2, 3] to [3, 3, 2] and [3].",
|
| 34 |
+
"Split [3, 3, 2] to [3, 3] and [2].",
|
| 35 |
+
"Split [3, 3] to [3] and [3].",
|
| 36 |
+
"1 <= n == nums.length <= 100",
|
| 37 |
+
"1 <= nums[i] <= 100",
|
| 38 |
+
"1 <= m <= 200"
|
| 39 |
+
],
|
| 40 |
+
"python_template": "class Solution(object):\n def canSplitArray(self, nums, m):\n \"\"\"\n :type nums: List[int]\n :type m: int\n :rtype: bool\n \"\"\"\n ",
|
| 41 |
+
"java_template": "class Solution {\n public boolean canSplitArray(List<Integer> nums, int m) {\n \n }\n}",
|
| 42 |
+
"metadata": {
|
| 43 |
+
"func_name": "canSplitArray"
|
| 44 |
+
}
|
| 45 |
+
}
|
check-if-matrix-is-x-matrix.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2398,
|
| 3 |
+
"name": "check-if-matrix-is-x-matrix",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-matrix-is-x-matrix/",
|
| 6 |
+
"date": "2022-06-19",
|
| 7 |
+
"task_description": "A square matrix is said to be an **X-Matrix** if **both** of the following conditions hold: All the elements in the diagonals of the matrix are **non-zero**. All other elements are 0. Given a 2D integer array `grid` of size `n x n` representing a square matrix, return `true`_ if _`grid`_ is an X-Matrix_. Otherwise, return `false`. **Example 1:** ``` **Input:** grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]] **Output:** true **Explanation:** Refer to the diagram above. An X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0. Thus, grid is an X-Matrix. ``` **Example 2:** ``` **Input:** grid = [[5,7,0],[0,3,1],[0,5,0]] **Output:** false **Explanation:** Refer to the diagram above. An X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0. Thus, grid is not an X-Matrix. ``` **Constraints:** `n == grid.length == grid[i].length` `3 <= n <= 100` `0 <= grid[i][j] <= 105`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "grid = [[5,7,0],[0,3,1],[0,5,0]]",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"n == grid.length == grid[i].length",
|
| 22 |
+
"3 <= n <= 100",
|
| 23 |
+
"0 <= grid[i][j] <= 105"
|
| 24 |
+
],
|
| 25 |
+
"python_template": "class Solution(object):\n def checkXMatrix(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: bool\n \"\"\"\n ",
|
| 26 |
+
"java_template": "class Solution {\n public boolean checkXMatrix(int[][] grid) {\n \n }\n}",
|
| 27 |
+
"metadata": {
|
| 28 |
+
"func_name": "checkXMatrix"
|
| 29 |
+
}
|
| 30 |
+
}
|
check-if-number-has-equal-digit-count-and-digit-value.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2377,
|
| 3 |
+
"name": "check-if-number-has-equal-digit-count-and-digit-value",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/",
|
| 6 |
+
"date": "2022-05-14",
|
| 7 |
+
"task_description": "You are given a **0-indexed** string `num` of length `n` consisting of digits. Return `true` _if for **every** index _`i`_ in the range _`0 <= i < n`_, the digit _`i`_ occurs _`num[i]`_ times in _`num`_, otherwise return _`false`. **Example 1:** ``` **Input:** num = \"1210\" **Output:** true **Explanation:** num[0] = '1'. The digit 0 occurs once in num. num[1] = '2'. The digit 1 occurs twice in num. num[2] = '1'. The digit 2 occurs once in num. num[3] = '0'. The digit 3 occurs zero times in num. The condition holds true for every index in \"1210\", so return true. ``` **Example 2:** ``` **Input:** num = \"030\" **Output:** false **Explanation:** num[0] = '0'. The digit 0 should occur zero times, but actually occurs twice in num. num[1] = '3'. The digit 1 should occur three times, but actually occurs zero times in num. num[2] = '0'. The digit 2 occurs zero times in num. The indices 0 and 1 both violate the condition, so return false. ``` **Constraints:** `n == num.length` `1 <= n <= 10` `num` consists of digits.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "num = \"1210\"",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "num = \"030\"",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"n == num.length",
|
| 22 |
+
"1 <= n <= 10",
|
| 23 |
+
"num consists of digits."
|
| 24 |
+
],
|
| 25 |
+
"python_template": "class Solution(object):\n def digitCount(self, num):\n \"\"\"\n :type num: str\n :rtype: bool\n \"\"\"\n ",
|
| 26 |
+
"java_template": "class Solution {\n public boolean digitCount(String num) {\n \n }\n}",
|
| 27 |
+
"metadata": {
|
| 28 |
+
"func_name": "digitCount"
|
| 29 |
+
}
|
| 30 |
+
}
|
check-if-point-is-reachable.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2635,
|
| 3 |
+
"name": "check-if-point-is-reachable",
|
| 4 |
+
"difficulty": "Hard",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-point-is-reachable/",
|
| 6 |
+
"date": "2023-01-07",
|
| 7 |
+
"task_description": "There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps. In one **step**, you can move from point `(x, y)` to any one of the following points: `(x, y - x)` `(x - y, y)` `(2 * x, y)` `(x, 2 * y)` Given two integers `targetX` and `targetY` representing the X-coordinate and Y-coordinate of your final position, return `true` _if you can reach the point from_ `(1, 1)` _using some number of steps, and _`false`_ otherwise_. **Example 1:** ``` **Input:** targetX = 6, targetY = 9 **Output:** false **Explanation:** It is impossible to reach (6,9) from (1,1) using any sequence of moves, so false is returned. ``` **Example 2:** ``` **Input:** targetX = 4, targetY = 7 **Output:** true **Explanation:** You can follow the path (1,1) -> (1,2) -> (1,4) -> (1,8) -> (1,7) -> (2,7) -> (4,7). ``` **Constraints:** `1 <= targetX, targetY <= 109`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "targetX = 6, targetY = 9",
|
| 12 |
+
"output": "false "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "targetX = 4, targetY = 7",
|
| 17 |
+
"output": "true "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"(x, y - x)",
|
| 22 |
+
"(x - y, y)",
|
| 23 |
+
"(2 * x, y)",
|
| 24 |
+
"(x, 2 * y)",
|
| 25 |
+
"1 <= targetX, targetY <= 109"
|
| 26 |
+
],
|
| 27 |
+
"python_template": "class Solution(object):\n def isReachable(self, targetX, targetY):\n \"\"\"\n :type targetX: int\n :type targetY: int\n :rtype: bool\n \"\"\"\n ",
|
| 28 |
+
"java_template": "class Solution {\n public boolean isReachable(int targetX, int targetY) {\n \n }\n}",
|
| 29 |
+
"metadata": {
|
| 30 |
+
"func_name": "isReachable"
|
| 31 |
+
}
|
| 32 |
+
}
|
check-if-strings-can-be-made-equal-with-operations-i.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2999,
|
| 3 |
+
"name": "check-if-strings-can-be-made-equal-with-operations-i",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i/",
|
| 6 |
+
"date": "2023-08-19",
|
| 7 |
+
"task_description": "You are given two strings `s1` and `s2`, both of length `4`, consisting of **lowercase** English letters. You can apply the following operation on any of the two strings **any** number of times: Choose any two indices `i` and `j` such that `j - i = 2`, then **swap** the two characters at those indices in the string. Return `true`_ if you can make the strings _`s1`_ and _`s2`_ equal, and _`false`_ otherwise_. **Example 1:** ``` **Input:** s1 = \"abcd\", s2 = \"cdab\" **Output:** true **Explanation:** We can do the following operations on s1: - Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbad\". - Choose the indices i = 1, j = 3. The resulting string is s1 = \"cdab\" = s2. ``` **Example 2:** ``` **Input:** s1 = \"abcd\", s2 = \"dacb\" **Output:** false **Explanation:** It is not possible to make the two strings equal. ``` **Constraints:** `s1.length == s2.length == 4` `s1` and `s2` consist only of lowercase English letters.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s1 = \"abcd\", s2 = \"cdab\"",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s1 = \"abcd\", s2 = \"dacb\"",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"Choose any two indices i and j such that j - i = 2, then swap the two characters at those indices in the string.",
|
| 22 |
+
"s1.length == s2.length == 4",
|
| 23 |
+
"s1 and s2 consist only of lowercase English letters."
|
| 24 |
+
],
|
| 25 |
+
"python_template": "class Solution(object):\n def canBeEqual(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: bool\n \"\"\"\n ",
|
| 26 |
+
"java_template": "class Solution {\n public boolean canBeEqual(String s1, String s2) {\n \n }\n}",
|
| 27 |
+
"metadata": {
|
| 28 |
+
"func_name": "canBeEqual"
|
| 29 |
+
}
|
| 30 |
+
}
|
check-if-strings-can-be-made-equal-with-operations-ii.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2978,
|
| 3 |
+
"name": "check-if-strings-can-be-made-equal-with-operations-ii",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-ii/",
|
| 6 |
+
"date": "2023-08-19",
|
| 7 |
+
"task_description": "You are given two strings `s1` and `s2`, both of length `n`, consisting of **lowercase** English letters. You can apply the following operation on **any** of the two strings **any** number of times: Choose any two indices `i` and `j` such that `i < j` and the difference `j - i` is **even**, then **swap** the two characters at those indices in the string. Return `true`_ if you can make the strings _`s1`_ and _`s2`_ equal, and _`false`_ otherwise_. **Example 1:** ``` **Input:** s1 = \"abcdba\", s2 = \"cabdab\" **Output:** true **Explanation:** We can apply the following operations on s1: - Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbadba\". - Choose the indices i = 2, j = 4. The resulting string is s1 = \"cbbdaa\". - Choose the indices i = 1, j = 5. The resulting string is s1 = \"cabdab\" = s2. ``` **Example 2:** ``` **Input:** s1 = \"abe\", s2 = \"bea\" **Output:** false **Explanation:** It is not possible to make the two strings equal. ``` **Constraints:** `n == s1.length == s2.length` `1 <= n <= 105` `s1` and `s2` consist only of lowercase English letters.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s1 = \"abcdba\", s2 = \"cabdab\"",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s1 = \"abe\", s2 = \"bea\"",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"Choose any two indices i and j such that i < j and the difference j - i is even, then swap the two characters at those indices in the string.",
|
| 22 |
+
"n == s1.length == s2.length",
|
| 23 |
+
"1 <= n <= 105",
|
| 24 |
+
"s1 and s2 consist only of lowercase English letters."
|
| 25 |
+
],
|
| 26 |
+
"python_template": "class Solution(object):\n def checkStrings(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: bool\n \"\"\"\n ",
|
| 27 |
+
"java_template": "class Solution {\n public boolean checkStrings(String s1, String s2) {\n \n }\n}",
|
| 28 |
+
"metadata": {
|
| 29 |
+
"func_name": "checkStrings"
|
| 30 |
+
}
|
| 31 |
+
}
|
check-if-there-is-a-valid-parentheses-string-path.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2349,
|
| 3 |
+
"name": "check-if-there-is-a-valid-parentheses-string-path",
|
| 4 |
+
"difficulty": "Hard",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-there-is-a-valid-parentheses-string-path/",
|
| 6 |
+
"date": "2022-05-01",
|
| 7 |
+
"task_description": "A parentheses string is a **non-empty** string consisting only of `'('` and `')'`. It is **valid** if **any** of the following conditions is **true**: It is `()`. It can be written as `AB` (`A` concatenated with `B`), where `A` and `B` are valid parentheses strings. It can be written as `(A)`, where `A` is a valid parentheses string. You are given an `m x n` matrix of parentheses `grid`. A **valid parentheses string path** in the grid is a path satisfying **all** of the following conditions: The path starts from the upper left cell `(0, 0)`. The path ends at the bottom-right cell `(m - 1, n - 1)`. The path only ever moves **down** or **right**. The resulting parentheses string formed by the path is **valid**. Return `true` _if there exists a **valid parentheses string path** in the grid._ Otherwise, return `false`. **Example 1:** ``` **Input:** grid = [[\"(\",\"(\",\"(\"],[\")\",\"(\",\")\"],[\"(\",\"(\",\")\"],[\"(\",\"(\",\")\"]] **Output:** true **Explanation:** The above diagram shows two possible paths that form valid parentheses strings. The first path shown results in the valid parentheses string \"()(())\". The second path shown results in the valid parentheses string \"((()))\". Note that there may be other valid parentheses string paths. ``` **Example 2:** ``` **Input:** grid = [[\")\",\")\"],[\"(\",\"(\"]] **Output:** false **Explanation:** The two possible paths form the parentheses strings \"))(\" and \")((\". Since neither of them are valid parentheses strings, we return false. ``` **Constraints:** `m == grid.length` `n == grid[i].length` `1 <= m, n <= 100` `grid[i][j]` is either `'('` or `')'`.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "grid = [[\"(\",\"(\",\"(\"],[\")\",\"(\",\")\"],[\"(\",\"(\",\")\"],[\"(\",\"(\",\")\"]]",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "grid = [[\")\",\")\"],[\"(\",\"(\"]]",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"It is ().",
|
| 22 |
+
"It can be written as AB (A concatenated with B), where A and B are valid parentheses strings.",
|
| 23 |
+
"It can be written as (A), where A is a valid parentheses string.",
|
| 24 |
+
"The path starts from the upper left cell (0, 0).",
|
| 25 |
+
"The path ends at the bottom-right cell (m - 1, n - 1).",
|
| 26 |
+
"The path only ever moves down or right.",
|
| 27 |
+
"The resulting parentheses string formed by the path is valid.",
|
| 28 |
+
"m == grid.length",
|
| 29 |
+
"n == grid[i].length",
|
| 30 |
+
"1 <= m, n <= 100",
|
| 31 |
+
"grid[i][j] is either '(' or ')'."
|
| 32 |
+
],
|
| 33 |
+
"python_template": "class Solution(object):\n def hasValidPath(self, grid):\n \"\"\"\n :type grid: List[List[str]]\n :rtype: bool\n \"\"\"\n ",
|
| 34 |
+
"java_template": "class Solution {\n public boolean hasValidPath(char[][] grid) {\n \n }\n}",
|
| 35 |
+
"metadata": {
|
| 36 |
+
"func_name": "hasValidPath"
|
| 37 |
+
}
|
| 38 |
+
}
|
check-if-there-is-a-valid-partition-for-the-array.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2443,
|
| 3 |
+
"name": "check-if-there-is-a-valid-partition-for-the-array",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-there-is-a-valid-partition-for-the-array/",
|
| 6 |
+
"date": "2022-07-31",
|
| 7 |
+
"task_description": "You are given a **0-indexed** integer array `nums`. You have to partition the array into one or more **contiguous** subarrays. We call a partition of the array **valid** if each of the obtained subarrays satisfies **one** of the following conditions: The subarray consists of **exactly** `2,` equal elements. For example, the subarray `[2,2]` is good. The subarray consists of **exactly** `3,` equal elements. For example, the subarray `[4,4,4]` is good. The subarray consists of **exactly** `3` consecutive increasing elements, that is, the difference between adjacent elements is `1`. For example, the subarray `[3,4,5]` is good, but the subarray `[1,3,5]` is not. Return `true`_ if the array has **at least** one valid partition_. Otherwise, return `false`. **Example 1:** ``` **Input:** nums = [4,4,4,5,6] **Output:** true **Explanation:** The array can be partitioned into the subarrays [4,4] and [4,5,6]. This partition is valid, so we return true. ``` **Example 2:** ``` **Input:** nums = [1,1,1,2] **Output:** false **Explanation:** There is no valid partition for this array. ``` **Constraints:** `2 <= nums.length <= 105` `1 <= nums[i] <= 106`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [4,4,4,5,6]",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [1,1,1,2]",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"2 <= nums.length <= 105",
|
| 22 |
+
"1 <= nums[i] <= 106"
|
| 23 |
+
],
|
| 24 |
+
"python_template": "class Solution(object):\n def validPartition(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n ",
|
| 25 |
+
"java_template": "class Solution {\n public boolean validPartition(int[] nums) {\n \n }\n}",
|
| 26 |
+
"metadata": {
|
| 27 |
+
"func_name": "validPartition"
|
| 28 |
+
}
|
| 29 |
+
}
|
check-if-two-chessboard-squares-have-the-same-color.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3553,
|
| 3 |
+
"name": "check-if-two-chessboard-squares-have-the-same-color",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-two-chessboard-squares-have-the-same-color/",
|
| 6 |
+
"date": "2024-08-25",
|
| 7 |
+
"task_description": "You are given two strings, `coordinate1` and `coordinate2`, representing the coordinates of a square on an `8 x 8` chessboard. Below is the chessboard for reference. Return `true` if these two squares have the same color and `false` otherwise. The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first (indicating its column), and the number second (indicating its row). **Example 1:** **Input:** coordinate1 = \"a1\", coordinate2 = \"c3\" **Output:** true **Explanation:** Both squares are black. **Example 2:** **Input:** coordinate1 = \"a1\", coordinate2 = \"h3\" **Output:** false **Explanation:** Square `\"a1\"` is black and `\"h3\"` is white. **Constraints:** `coordinate1.length == coordinate2.length == 2` `'a' <= coordinate1[0], coordinate2[0] <= 'h'` `'1' <= coordinate1[1], coordinate2[1] <= '8'`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "coordinate1 = \"a1\", coordinate2 = \"c3\"",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "coordinate1 = \"a1\", coordinate2 = \"h3\"",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"coordinate1.length == coordinate2.length == 2",
|
| 22 |
+
"'a' <= coordinate1[0], coordinate2[0] <= 'h'",
|
| 23 |
+
"'1' <= coordinate1[1], coordinate2[1] <= '8'"
|
| 24 |
+
],
|
| 25 |
+
"python_template": "class Solution(object):\n def checkTwoChessboards(self, coordinate1, coordinate2):\n \"\"\"\n :type coordinate1: str\n :type coordinate2: str\n :rtype: bool\n \"\"\"\n ",
|
| 26 |
+
"java_template": "class Solution {\n public boolean checkTwoChessboards(String coordinate1, String coordinate2) {\n \n }\n}",
|
| 27 |
+
"metadata": {
|
| 28 |
+
"func_name": "checkTwoChessboards"
|
| 29 |
+
}
|
| 30 |
+
}
|
circular-sentence.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2580,
|
| 3 |
+
"name": "circular-sentence",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/circular-sentence/",
|
| 6 |
+
"date": "2022-11-27",
|
| 7 |
+
"task_description": "A **sentence** is a list of words that are separated by a** single** space with no leading or trailing spaces. For example, `\"Hello World\"`, `\"HELLO\"`, `\"hello world hello world\"` are all sentences. Words consist of **only** uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different. A sentence is **circular **if: The last character of each word in the sentence is equal to the first character of its next word. The last character of the last word is equal to the first character of the first word. For example, `\"leetcode exercises sound delightful\"`, `\"eetcode\"`, `\"leetcode eats soul\" `are all circular sentences. However, `\"Leetcode is cool\"`, `\"happy Leetcode\"`, `\"Leetcode\"` and `\"I like Leetcode\"` are **not** circular sentences. Given a string `sentence`, return `true`_ if it is circular_. Otherwise, return `false`. **Example 1:** ``` **Input:** sentence = \"leetcode exercises sound delightful\" **Output:** true **Explanation:** The words in sentence are [\"leetcode\", \"exercises\", \"sound\", \"delightful\"]. - leetcode's last character is equal to exercises's first character. - exercises's last character is equal to sound's first character. - sound's last character is equal to delightful's first character. - delightful's last character is equal to leetcode's first character. The sentence is circular. ``` **Example 2:** ``` **Input:** sentence = \"eetcode\" **Output:** true **Explanation:** The words in sentence are [\"eetcode\"]. - eetcode's last character is equal to eetcode's first character. The sentence is circular. ``` **Example 3:** ``` **Input:** sentence = \"Leetcode is cool\" **Output:** false **Explanation:** The words in sentence are [\"Leetcode\", \"is\", \"cool\"]. - Leetcode's last character is **not** equal to is's first character. The sentence is **not** circular. ``` **Constraints:** `1 <= sentence.length <= 500` `sentence` consist of only lowercase and uppercase English letters and spaces. The words in `sentence` are separated by a single space. There are no leading or trailing spaces.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "sentence = \"leetcode exercises sound delightful\"",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "sentence = \"eetcode\"",
|
| 17 |
+
"output": "true "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "sentence = \"Leetcode is cool\"",
|
| 22 |
+
"output": "false "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"constraints": [
|
| 26 |
+
"For example, \"Hello World\", \"HELLO\", \"hello world hello world\" are all sentences.",
|
| 27 |
+
"The last character of each word in the sentence is equal to the first character of its next word.",
|
| 28 |
+
"The last character of the last word is equal to the first character of the first word.",
|
| 29 |
+
"1 <= sentence.length <= 500",
|
| 30 |
+
"sentence consist of only lowercase and uppercase English letters and spaces.",
|
| 31 |
+
"The words in sentence are separated by a single space.",
|
| 32 |
+
"There are no leading or trailing spaces."
|
| 33 |
+
],
|
| 34 |
+
"python_template": "class Solution(object):\n def isCircularSentence(self, sentence):\n \"\"\"\n :type sentence: str\n :rtype: bool\n \"\"\"\n ",
|
| 35 |
+
"java_template": "class Solution {\n public boolean isCircularSentence(String sentence) {\n \n }\n}",
|
| 36 |
+
"metadata": {
|
| 37 |
+
"func_name": "isCircularSentence"
|
| 38 |
+
}
|
| 39 |
+
}
|
clear-digits.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3447,
|
| 3 |
+
"name": "clear-digits",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/clear-digits/",
|
| 6 |
+
"date": "2024-05-25",
|
| 7 |
+
"task_description": "You are given a string `s`. Your task is to remove **all** digits by doing this operation repeatedly: Delete the _first_ digit and the **closest** non-digit character to its _left_. Return the resulting string after removing all digits. **Note** that the operation _cannot_ be performed on a digit that does not have any non-digit character to its left. **Example 1:** **Input:** s = \"abc\" **Output:** \"abc\" **Explanation:** There is no digit in the string. **Example 2:** **Input:** s = \"cb34\" **Output:** \"\" **Explanation:** First, we apply the operation on `s[2]`, and `s` becomes `\"c4\"`. Then we apply the operation on `s[1]`, and `s` becomes `\"\"`. **Constraints:** `1 <= s.length <= 100` `s` consists only of lowercase English letters and digits. The input is generated such that it is possible to delete all digits.",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"abc\"",
|
| 12 |
+
"output": "\"abc\" "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"cb34\"",
|
| 17 |
+
"output": "\"\" "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"Delete the first digit and the closest non-digit character to its left.",
|
| 22 |
+
"1 <= s.length <= 100",
|
| 23 |
+
"s consists only of lowercase English letters and digits.",
|
| 24 |
+
"The input is generated such that it is possible to delete all digits."
|
| 25 |
+
],
|
| 26 |
+
"python_template": "class Solution(object):\n def clearDigits(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n ",
|
| 27 |
+
"java_template": "class Solution {\n public String clearDigits(String s) {\n \n }\n}",
|
| 28 |
+
"metadata": {
|
| 29 |
+
"func_name": "clearDigits"
|
| 30 |
+
}
|
| 31 |
+
}
|
closest-equal-element-queries.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3750,
|
| 3 |
+
"name": "closest-equal-element-queries",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/closest-equal-element-queries/",
|
| 6 |
+
"date": "2025-03-09",
|
| 7 |
+
"task_description": "You are given a **circular** array `nums` and an array `queries`. For each query `i`, you have to find the following: The **minimum** distance between the element at index `queries[i]` and **any** other index `j` in the **circular** array, where `nums[j] == nums[queries[i]]`. If no such index exists, the answer for that query should be -1. Return an array `answer` of the **same** size as `queries`, where `answer[i]` represents the result for query `i`. **Example 1:** **Input:** nums = [1,3,1,4,1,3,2], queries = [0,3,5] **Output:** [2,-1,3] **Explanation:** Query 0: The element at `queries[0] = 0` is `nums[0] = 1`. The nearest index with the same value is 2, and the distance between them is 2. Query 1: The element at `queries[1] = 3` is `nums[3] = 4`. No other index contains 4, so the result is -1. Query 2: The element at `queries[2] = 5` is `nums[5] = 3`. The nearest index with the same value is 1, and the distance between them is 3 (following the circular path: `5 -> 6 -> 0 -> 1`). **Example 2:** **Input:** nums = [1,2,3,4], queries = [0,1,2,3] **Output:** [-1,-1,-1,-1] **Explanation:** Each value in `nums` is unique, so no index shares the same value as the queried element. This results in -1 for all queries. **Constraints:** `1 <= queries.length <= nums.length <= 105` `1 <= nums[i] <= 106` `0 <= queries[i] < nums.length`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [1,3,1,4,1,3,2], queries = [0,3,5]",
|
| 12 |
+
"output": "[2,-1,3] "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [1,2,3,4], queries = [0,1,2,3]",
|
| 17 |
+
"output": "[-1,-1,-1,-1] "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"The minimum distance between the element at index queries[i] and any other index j in the circular array, where nums[j] == nums[queries[i]]. If no such index exists, the answer for that query should be -1.",
|
| 22 |
+
"Query 0: The element at queries[0] = 0 is nums[0] = 1. The nearest index with the same value is 2, and the distance between them is 2.",
|
| 23 |
+
"Query 1: The element at queries[1] = 3 is nums[3] = 4. No other index contains 4, so the result is -1.",
|
| 24 |
+
"Query 2: The element at queries[2] = 5 is nums[5] = 3. The nearest index with the same value is 1, and the distance between them is 3 (following the circular path: 5 -> 6 -> 0 -> 1).",
|
| 25 |
+
"1 <= queries.length <= nums.length <= 105",
|
| 26 |
+
"1 <= nums[i] <= 106",
|
| 27 |
+
"0 <= queries[i] < nums.length"
|
| 28 |
+
],
|
| 29 |
+
"python_template": "class Solution(object):\n def solveQueries(self, nums, queries):\n \"\"\"\n :type nums: List[int]\n :type queries: List[int]\n :rtype: List[int]\n \"\"\"\n ",
|
| 30 |
+
"java_template": "class Solution {\n public List<Integer> solveQueries(int[] nums, int[] queries) {\n \n }\n}",
|
| 31 |
+
"metadata": {
|
| 32 |
+
"func_name": "solveQueries"
|
| 33 |
+
}
|
| 34 |
+
}
|
closest-prime-numbers-in-range.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2610,
|
| 3 |
+
"name": "closest-prime-numbers-in-range",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/closest-prime-numbers-in-range/",
|
| 6 |
+
"date": "2022-12-25",
|
| 7 |
+
"task_description": "Given two positive integers `left` and `right`, find the two integers `num1` and `num2` such that: `left <= num1 < num2 <= right `. Both `num1` and `num2` are prime numbers. `num2 - num1` is the **minimum** amongst all other pairs satisfying the above conditions. Return the positive integer array `ans = [num1, num2]`. If there are multiple pairs satisfying these conditions, return the one with the **smallest** `num1` value. If no such numbers exist, return `[-1, -1]`_._ **Example 1:** ``` **Input:** left = 10, right = 19 **Output:** [11,13] **Explanation:** The prime numbers between 10 and 19 are 11, 13, 17, and 19. The closest gap between any pair is 2, which can be achieved by [11,13] or [17,19]. Since 11 is smaller than 17, we return the first pair. ``` **Example 2:** ``` **Input:** left = 4, right = 6 **Output:** [-1,-1] **Explanation:** There exists only one prime number in the given range, so the conditions cannot be satisfied. ``` **Constraints:** `1 <= left <= right <= 106`",
|
| 8 |
+
"test_case": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "left = 10, right = 19",
|
| 12 |
+
"output": "[11,13] "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "left = 4, right = 6",
|
| 17 |
+
"output": "[-1,-1] "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"constraints": [
|
| 21 |
+
"left <= num1 < num2 <= right .",
|
| 22 |
+
"Both num1 and num2 are prime numbers.",
|
| 23 |
+
"num2 - num1 is the minimum amongst all other pairs satisfying the above conditions.",
|
| 24 |
+
"1 <= left <= right <= 106"
|
| 25 |
+
],
|
| 26 |
+
"python_template": "class Solution(object):\n def closestPrimes(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: List[int]\n \"\"\"\n ",
|
| 27 |
+
"java_template": "class Solution {\n public int[] closestPrimes(int left, int right) {\n \n }\n}",
|
| 28 |
+
"metadata": {
|
| 29 |
+
"func_name": "closestPrimes"
|
| 30 |
+
}
|
| 31 |
+
}
|