DataRepo commited on
Commit
a5c8d73
·
verified ·
1 Parent(s): 4097b71

Upload part 2 of 2

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. minimum-operations-to-make-binary-array-elements-equal-to-one-ii.json +35 -0
  2. minimum-operations-to-make-columns-strictly-increasing.json +36 -0
  3. minimum-operations-to-make-median-of-array-equal-to-k.json +35 -0
  4. minimum-operations-to-make-the-array-alternating.json +31 -0
  5. minimum-operations-to-maximize-last-elements-in-arrays.json +37 -0
  6. minimum-operations-to-write-the-letter-y-on-a-grid.json +37 -0
  7. minimum-penalty-for-a-shop.json +38 -0
  8. minimum-processing-time.json +32 -0
  9. minimum-recolors-to-get-k-consecutive-black-blocks.json +31 -0
  10. minimum-replacements-to-sort-the-array.json +30 -0
  11. minimum-reverse-operations.json +47 -0
  12. minimum-right-shifts-to-sort-the-array.json +35 -0
  13. minimum-rounds-to-complete-all-tasks.json +29 -0
  14. minimum-score-after-removals-on-a-tree.json +36 -0
  15. minimum-score-by-changing-two-elements.json +38 -0
  16. minimum-score-of-a-path-between-two-cities.json +38 -0
  17. minimum-seconds-to-equalize-a-circular-array.json +35 -0
  18. minimum-size-subarray-in-infinite-array.json +35 -0
  19. minimum-string-length-after-removing-substrings.json +29 -0
  20. minimum-substring-partition-of-equal-character-frequency.json +29 -0
  21. minimum-sum-of-mountain-triplets-i.json +36 -0
  22. minimum-sum-of-mountain-triplets-ii.json +36 -0
  23. minimum-sum-of-squared-difference.json +31 -0
  24. minimum-sum-of-values-by-dividing-array.json +36 -0
  25. minimum-swaps-to-group-all-1s-together-ii.json +34 -0
  26. minimum-time-to-break-locks-i.json +36 -0
  27. minimum-time-to-complete-all-tasks.json +31 -0
  28. minimum-time-to-complete-trips.json +29 -0
  29. minimum-time-to-make-array-sum-at-most-x.json +33 -0
  30. minimum-time-to-remove-all-cars-containing-illegal-goods.json +29 -0
  31. minimum-time-to-repair-cars.json +30 -0
  32. minimum-time-to-revert-word-to-initial-state-i.json +37 -0
  33. minimum-time-to-revert-word-to-initial-state-ii.json +37 -0
  34. minimum-time-to-visit-disappearing-nodes.json +45 -0
  35. minimum-total-cost-to-make-arrays-unequal.json +35 -0
  36. minimum-total-distance-traveled.json +37 -0
  37. minimum-weighted-subgraph-with-the-required-paths.json +34 -0
  38. minimum-white-tiles-after-covering-with-carpets.json +32 -0
  39. modify-graph-edge-weights.json +42 -0
  40. modify-the-matrix.json +32 -0
  41. most-frequent-even-element.json +34 -0
  42. most-frequent-ids.json +34 -0
  43. most-frequent-number-following-key-in-an-array.json +33 -0
  44. most-frequent-prime.json +39 -0
  45. most-popular-video-creator.json +34 -0
  46. most-profitable-path-in-a-tree.json +46 -0
  47. move-pieces-to-obtain-a-string.json +37 -0
  48. movement-of-robots.json +40 -0
  49. neighboring-bitwise-xor.json +38 -0
  50. neither-minimum-nor-maximum.json +35 -0
minimum-operations-to-make-binary-array-elements-equal-to-one-ii.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3477,
3
+ "name": "minimum-operations-to-make-binary-array-elements-equal-to-one-ii",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-operations-to-make-binary-array-elements-equal-to-one-ii/",
6
+ "date": "2024-06-08",
7
+ "task_description": "You are given a binary array `nums`. You can do the following operation on the array **any** number of times (possibly zero): Choose **any** index `i` from the array and **flip** **all** the elements from index `i` to the end of the array. **Flipping** an element means changing its value from 0 to 1, and from 1 to 0. Return the **minimum** number of operations required to make all elements in `nums` equal to 1. **Example 1:** **Input:** nums = [0,1,1,0,1] **Output:** 4 **Explanation:** We can do the following operations: Choose the index `i = 1`. The resulting array will be `nums = [0,**0**,**0**,**1**,**0**]`. Choose the index `i = 0`. The resulting array will be `nums = [**1**,**1**,**1**,**0**,**1**]`. Choose the index `i = 4`. The resulting array will be `nums = [1,1,1,0,**0**]`. Choose the index `i = 3`. The resulting array will be `nums = [1,1,1,**1**,**1**]`. **Example 2:** **Input:** nums = [1,0,0,0] **Output:** 1 **Explanation:** We can do the following operation: Choose the index `i = 1`. The resulting array will be `nums = [1,**1**,**1**,**1**]`. **Constraints:** `1 <= nums.length <= 105` `0 <= nums[i] <= 1`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [0,1,1,0,1]",
12
+ "output": "4 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [1,0,0,0]",
17
+ "output": "1 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "Choose any index i from the array and flip all the elements from index i to the end of the array.",
22
+ "Choose the index i = 1. The resulting array will be nums = [0,0,0,1,0].",
23
+ "Choose the index i = 0. The resulting array will be nums = [1,1,1,0,1].",
24
+ "Choose the index i = 4. The resulting array will be nums = [1,1,1,0,0].",
25
+ "Choose the index i = 3. The resulting array will be nums = [1,1,1,1,1].",
26
+ "Choose the index i = 1. The resulting array will be nums = [1,1,1,1].",
27
+ "1 <= nums.length <= 105",
28
+ "0 <= nums[i] <= 1"
29
+ ],
30
+ "python_template": "class Solution(object):\n def minOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
31
+ "java_template": "class Solution {\n public int minOperations(int[] nums) {\n \n }\n}",
32
+ "metadata": {
33
+ "func_name": "minOperations"
34
+ }
35
+ }
minimum-operations-to-make-columns-strictly-increasing.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3691,
3
+ "name": "minimum-operations-to-make-columns-strictly-increasing",
4
+ "difficulty": "Easy",
5
+ "link": "https://leetcode.com/problems/minimum-operations-to-make-columns-strictly-increasing/",
6
+ "date": "2024-12-22",
7
+ "task_description": "You are given a `m x n` matrix `grid` consisting of non-negative integers. In one operation, you can increment the value of any `grid[i][j]` by 1. Return the **minimum** number of operations needed to make all columns of `grid` **strictly increasing**. **Example 1:** **Input:** grid = [[3,2],[1,3],[3,4],[0,1]] **Output:** 15 **Explanation:** To make the `0th` column strictly increasing, we can apply 3 operations on `grid[1][0]`, 2 operations on `grid[2][0]`, and 6 operations on `grid[3][0]`. To make the `1st` column strictly increasing, we can apply 4 operations on `grid[3][1]`. **Example 2:** **Input:** grid = [[3,2,1],[2,1,0],[1,2,3]] **Output:** 12 **Explanation:** To make the `0th` column strictly increasing, we can apply 2 operations on `grid[1][0]`, and 4 operations on `grid[2][0]`. To make the `1st` column strictly increasing, we can apply 2 operations on `grid[1][1]`, and 2 operations on `grid[2][1]`. To make the `2nd` column strictly increasing, we can apply 2 operations on `grid[1][2]`. **Constraints:** `m == grid.length` `n == grid[i].length` `1 <= m, n <= 50` `0 <= grid[i][j] < 2500` ``` ```",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "grid = [[3,2],[1,3],[3,4],[0,1]]",
12
+ "output": "15 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "grid = [[3,2,1],[2,1,0],[1,2,3]]",
17
+ "output": "12 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "To make the 0th column strictly increasing, we can apply 3 operations on grid[1][0], 2 operations on grid[2][0], and 6 operations on grid[3][0].",
22
+ "To make the 1st column strictly increasing, we can apply 4 operations on grid[3][1].",
23
+ "To make the 0th column strictly increasing, we can apply 2 operations on grid[1][0], and 4 operations on grid[2][0].",
24
+ "To make the 1st column strictly increasing, we can apply 2 operations on grid[1][1], and 2 operations on grid[2][1].",
25
+ "To make the 2nd column strictly increasing, we can apply 2 operations on grid[1][2].",
26
+ "m == grid.length",
27
+ "n == grid[i].length",
28
+ "1 <= m, n <= 50",
29
+ "0 <= grid[i][j] < 2500"
30
+ ],
31
+ "python_template": "class Solution(object):\n def minimumOperations(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n ",
32
+ "java_template": "class Solution {\n public int minimumOperations(int[][] grid) {\n \n }\n}",
33
+ "metadata": {
34
+ "func_name": "minimumOperations"
35
+ }
36
+ }
minimum-operations-to-make-median-of-array-equal-to-k.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3387,
3
+ "name": "minimum-operations-to-make-median-of-array-equal-to-k",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-operations-to-make-median-of-array-equal-to-k/",
6
+ "date": "2024-03-31",
7
+ "task_description": "You are given an integer array `nums` and a **non-negative** integer `k`. In one operation, you can increase or decrease any element by 1. Return the **minimum** number of operations needed to make the **median** of `nums` _equal_ to `k`. The median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the larger of the two values is taken. **Example 1:** **Input:** nums = [2,5,6,8,5], k = 4 **Output:** 2 **Explanation:** We can subtract one from `nums[1]` and `nums[4]` to obtain `[2, 4, 6, 8, 4]`. The median of the resulting array is equal to `k`. **Example 2:** **Input:** nums = [2,5,6,8,5], k = 7 **Output:** 3 **Explanation:** We can add one to `nums[1]` twice and add one to `nums[2]` once to obtain `[2, 7, 7, 8, 5]`. **Example 3:** **Input:** nums = [1,2,3,4,5,6], k = 4 **Output:** 0 **Explanation:** The median of the array is already equal to `k`. **Constraints:** `1 <= nums.length <= 2 * 105` `1 <= nums[i] <= 109` `1 <= k <= 109`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [2,5,6,8,5], k = 4",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [2,5,6,8,5], k = 7",
17
+ "output": "3 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums = [1,2,3,4,5,6], k = 4",
22
+ "output": "0 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "1 <= nums.length <= 2 * 105",
27
+ "1 <= nums[i] <= 109",
28
+ "1 <= k <= 109"
29
+ ],
30
+ "python_template": "class Solution(object):\n def minOperationsToMakeMedianK(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n ",
31
+ "java_template": "class Solution {\n public long minOperationsToMakeMedianK(int[] nums, int k) {\n \n }\n}",
32
+ "metadata": {
33
+ "func_name": "minOperationsToMakeMedianK"
34
+ }
35
+ }
minimum-operations-to-make-the-array-alternating.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2289,
3
+ "name": "minimum-operations-to-make-the-array-alternating",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-operations-to-make-the-array-alternating/",
6
+ "date": "2022-02-06",
7
+ "task_description": "You are given a **0-indexed** array `nums` consisting of `n` positive integers. The array `nums` is called **alternating** if: `nums[i - 2] == nums[i]`, where `2 <= i <= n - 1`. `nums[i - 1] != nums[i]`, where `1 <= i <= n - 1`. In one **operation**, you can choose an index `i` and **change** `nums[i]` into **any** positive integer. Return _the **minimum number of operations** required to make the array alternating_. **Example 1:** ``` **Input:** nums = [3,1,3,2,4,3] **Output:** 3 **Explanation:** One way to make the array alternating is by converting it to [3,1,3,**1**,**3**,**1**]. The number of operations required in this case is 3. It can be proven that it is not possible to make the array alternating in less than 3 operations. ``` **Example 2:** ``` **Input:** nums = [1,2,2,2,2] **Output:** 2 **Explanation:** One way to make the array alternating is by converting it to [1,2,**1**,2,**1**]. The number of operations required in this case is 2. Note that the array cannot be converted to [**2**,2,2,2,2] because in this case nums[0] == nums[1] which violates the conditions of an alternating array. ``` **Constraints:** `1 <= nums.length <= 105` `1 <= nums[i] <= 105`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [3,1,3,2,4,3]",
12
+ "output": "3 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [1,2,2,2,2]",
17
+ "output": "2 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "nums[i - 2] == nums[i], where 2 <= i <= n - 1.",
22
+ "nums[i - 1] != nums[i], where 1 <= i <= n - 1.",
23
+ "1 <= nums.length <= 105",
24
+ "1 <= nums[i] <= 105"
25
+ ],
26
+ "python_template": "class Solution(object):\n def minimumOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
27
+ "java_template": "class Solution {\n public int minimumOperations(int[] nums) {\n \n }\n}",
28
+ "metadata": {
29
+ "func_name": "minimumOperations"
30
+ }
31
+ }
minimum-operations-to-maximize-last-elements-in-arrays.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3190,
3
+ "name": "minimum-operations-to-maximize-last-elements-in-arrays",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-operations-to-maximize-last-elements-in-arrays/",
6
+ "date": "2023-11-05",
7
+ "task_description": "You are given two **0-indexed** integer arrays, `nums1` and `nums2`, both having length `n`. You are allowed to perform a series of **operations** (**possibly none**). In an operation, you select an index `i` in the range `[0, n - 1]` and **swap** the values of `nums1[i]` and `nums2[i]`. Your task is to find the **minimum** number of operations required to satisfy the following conditions: `nums1[n - 1]` is equal to the **maximum value** among all elements of `nums1`, i.e., `nums1[n - 1] = max(nums1[0], nums1[1], ..., nums1[n - 1])`. `nums2[n - 1]` is equal to the **maximum** **value** among all elements of `nums2`, i.e., `nums2[n - 1] = max(nums2[0], nums2[1], ..., nums2[n - 1])`. Return _an integer denoting the **minimum** number of operations needed to meet **both** conditions_, _or _`-1`_ if it is **impossible** to satisfy both conditions._ **Example 1:** ``` **Input:** nums1 = [1,2,7], nums2 = [4,5,3] **Output:** 1 **Explanation:** In this example, an operation can be performed using index i = 2. When nums1[2] and nums2[2] are swapped, nums1 becomes [1,2,3] and nums2 becomes [4,5,7]. Both conditions are now satisfied. It can be shown that the minimum number of operations needed to be performed is 1. So, the answer is 1. ``` **Example 2:** ``` **Input:** nums1 = [2,3,4,5,9], nums2 = [8,8,4,4,4] **Output:** 2 **Explanation:** In this example, the following operations can be performed: First operation using index i = 4. When nums1[4] and nums2[4] are swapped, nums1 becomes [2,3,4,5,4], and nums2 becomes [8,8,4,4,9]. Another operation using index i = 3. When nums1[3] and nums2[3] are swapped, nums1 becomes [2,3,4,4,4], and nums2 becomes [8,8,4,5,9]. Both conditions are now satisfied. It can be shown that the minimum number of operations needed to be performed is 2. So, the answer is 2. ``` **Example 3:** ``` **Input:** nums1 = [1,5,4], nums2 = [2,5,3] **Output:** -1 **Explanation:** In this example, it is not possible to satisfy both conditions. So, the answer is -1. ``` **Constraints:** `1 <= n == nums1.length == nums2.length <= 1000` `1 <= nums1[i] <= 109` `1 <= nums2[i] <= 109`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums1 = [1,2,7], nums2 = [4,5,3]",
12
+ "output": "1 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums1 = [2,3,4,5,9], nums2 = [8,8,4,4,4]",
17
+ "output": "2 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums1 = [1,5,4], nums2 = [2,5,3]",
22
+ "output": "-1 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "nums1[n - 1] is equal to the maximum value among all elements of nums1, i.e., nums1[n - 1] = max(nums1[0], nums1[1], ..., nums1[n - 1]).",
27
+ "nums2[n - 1] is equal to the maximum value among all elements of nums2, i.e., nums2[n - 1] = max(nums2[0], nums2[1], ..., nums2[n - 1]).",
28
+ "1 <= n == nums1.length == nums2.length <= 1000",
29
+ "1 <= nums1[i] <= 109",
30
+ "1 <= nums2[i] <= 109"
31
+ ],
32
+ "python_template": "class Solution(object):\n def minOperations(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"\n ",
33
+ "java_template": "class Solution {\n public int minOperations(int[] nums1, int[] nums2) {\n \n }\n}",
34
+ "metadata": {
35
+ "func_name": "minOperations"
36
+ }
37
+ }
minimum-operations-to-write-the-letter-y-on-a-grid.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3335,
3
+ "name": "minimum-operations-to-write-the-letter-y-on-a-grid",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-operations-to-write-the-letter-y-on-a-grid/",
6
+ "date": "2024-02-25",
7
+ "task_description": "You are given a **0-indexed** `n x n` grid where `n` is odd, and `grid[r][c]` is `0`, `1`, or `2`. We say that a cell belongs to the Letter **Y** if it belongs to one of the following: The diagonal starting at the top-left cell and ending at the center cell of the grid. The diagonal starting at the top-right cell and ending at the center cell of the grid. The vertical line starting at the center cell and ending at the bottom border of the grid. The Letter **Y** is written on the grid if and only if: All values at cells belonging to the Y are equal. All values at cells not belonging to the Y are equal. The values at cells belonging to the Y are different from the values at cells not belonging to the Y. Return _the **minimum** number of operations needed to write the letter Y on the grid given that in one operation you can change the value at any cell to_ `0`_,_ `1`_,_ _or_ `2`_._ **Example 1:** ``` **Input:** grid = [[1,2,2],[1,1,0],[0,1,0]] **Output:** 3 **Explanation:** We can write Y on the grid by applying the changes highlighted in blue in the image above. After the operations, all cells that belong to Y, denoted in bold, have the same value of 1 while those that do not belong to Y are equal to 0. It can be shown that 3 is the minimum number of operations needed to write Y on the grid. ``` **Example 2:** ``` **Input:** grid = [[0,1,0,1,0],[2,1,0,1,2],[2,2,2,0,1],[2,2,2,2,2],[2,1,2,2,2]] **Output:** 12 **Explanation:** We can write Y on the grid by applying the changes highlighted in blue in the image above. After the operations, all cells that belong to Y, denoted in bold, have the same value of 0 while those that do not belong to Y are equal to 2. It can be shown that 12 is the minimum number of operations needed to write Y on the grid. ``` **Constraints:** `3 <= n <= 49 ` `n == grid.length == grid[i].length` `0 <= grid[i][j] <= 2` `n` is odd.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "grid = [[1,2,2],[1,1,0],[0,1,0]]",
12
+ "output": "3 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "grid = [[0,1,0,1,0],[2,1,0,1,2],[2,2,2,0,1],[2,2,2,2,2],[2,1,2,2,2]]",
17
+ "output": "12 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "The diagonal starting at the top-left cell and ending at the center cell of the grid.",
22
+ "The diagonal starting at the top-right cell and ending at the center cell of the grid.",
23
+ "The vertical line starting at the center cell and ending at the bottom border of the grid.",
24
+ "All values at cells belonging to the Y are equal.",
25
+ "All values at cells not belonging to the Y are equal.",
26
+ "The values at cells belonging to the Y are different from the values at cells not belonging to the Y.",
27
+ "3 <= n <= 49",
28
+ "n == grid.length == grid[i].length",
29
+ "0 <= grid[i][j] <= 2",
30
+ "n is odd."
31
+ ],
32
+ "python_template": "class Solution(object):\n def minimumOperationsToWriteY(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n ",
33
+ "java_template": "class Solution {\n public int minimumOperationsToWriteY(int[][] grid) {\n \n }\n}",
34
+ "metadata": {
35
+ "func_name": "minimumOperationsToWriteY"
36
+ }
37
+ }
minimum-penalty-for-a-shop.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2576,
3
+ "name": "minimum-penalty-for-a-shop",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-penalty-for-a-shop/",
6
+ "date": "2022-11-12",
7
+ "task_description": "You are given the customer visit log of a shop represented by a **0-indexed** string `customers` consisting only of characters `'N'` and `'Y'`: if the `ith` character is `'Y'`, it means that customers come at the `ith` hour whereas `'N'` indicates that no customers come at the `ith` hour. If the shop closes at the `jth` hour (`0 <= j <= n`), the **penalty** is calculated as follows: For every hour when the shop is open and no customers come, the penalty increases by `1`. For every hour when the shop is closed and customers come, the penalty increases by `1`. Return_ the **earliest** hour at which the shop must be closed to incur a **minimum** penalty._ **Note** that if a shop closes at the `jth` hour, it means the shop is closed at the hour `j`. **Example 1:** ``` **Input:** customers = \"YYNY\" **Output:** 2 **Explanation:** - Closing the shop at the 0th hour incurs in 1+1+0+1 = 3 penalty. - Closing the shop at the 1st hour incurs in 0+1+0+1 = 2 penalty. - Closing the shop at the 2nd hour incurs in 0+0+0+1 = 1 penalty. - Closing the shop at the 3rd hour incurs in 0+0+1+1 = 2 penalty. - Closing the shop at the 4th hour incurs in 0+0+1+0 = 1 penalty. Closing the shop at 2nd or 4th hour gives a minimum penalty. Since 2 is earlier, the optimal closing time is 2. ``` **Example 2:** ``` **Input:** customers = \"NNNNN\" **Output:** 0 **Explanation:** It is best to close the shop at the 0th hour as no customers arrive. ``` **Example 3:** ``` **Input:** customers = \"YYYY\" **Output:** 4 **Explanation:** It is best to close the shop at the 4th hour as customers arrive at each hour. ``` **Constraints:** `1 <= customers.length <= 105` `customers` consists only of characters `'Y'` and `'N'`.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "customers = \"YYNY\"",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "customers = \"NNNNN\"",
17
+ "output": "0 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "customers = \"YYYY\"",
22
+ "output": "4 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "if the ith character is 'Y', it means that customers come at the ith hour",
27
+ "whereas 'N' indicates that no customers come at the ith hour.",
28
+ "For every hour when the shop is open and no customers come, the penalty increases by 1.",
29
+ "For every hour when the shop is closed and customers come, the penalty increases by 1.",
30
+ "1 <= customers.length <= 105",
31
+ "customers consists only of characters 'Y' and 'N'."
32
+ ],
33
+ "python_template": "class Solution(object):\n def bestClosingTime(self, customers):\n \"\"\"\n :type customers: str\n :rtype: int\n \"\"\"\n ",
34
+ "java_template": "class Solution {\n public int bestClosingTime(String customers) {\n \n }\n}",
35
+ "metadata": {
36
+ "func_name": "bestClosingTime"
37
+ }
38
+ }
minimum-processing-time.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3151,
3
+ "name": "minimum-processing-time",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-processing-time/",
6
+ "date": "2023-10-01",
7
+ "task_description": "You have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors. Each task must be assigned to a unique core, and each core can only be used once. You are given an array `processorTime` representing the time each processor becomes available and an array `tasks` representing how long each task takes to complete. Return the _minimum_ time needed to complete all tasks. **Example 1:** **Input:** processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5] **Output:** 16 **Explanation:** Assign the tasks at indices 4, 5, 6, 7 to the first processor which becomes available at `time = 8`, and the tasks at indices 0, 1, 2, 3 to the second processor which becomes available at `time = 10`. The time taken by the first processor to finish the execution of all tasks is `max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16`. The time taken by the second processor to finish the execution of all tasks is `max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13`. **Example 2:** **Input:** processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3] **Output:** 23 **Explanation:** Assign the tasks at indices 1, 4, 5, 6 to the first processor and the others to the second processor. The time taken by the first processor to finish the execution of all tasks is `max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18`. The time taken by the second processor to finish the execution of all tasks is `max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23`. **Constraints:** `1 <= n == processorTime.length <= 25000` `1 <= tasks.length <= 105` `0 <= processorTime[i] <= 109` `1 <= tasks[i] <= 109` `tasks.length == 4 * n`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5]",
12
+ "output": "16 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]",
17
+ "output": "23 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "1 <= n == processorTime.length <= 25000",
22
+ "1 <= tasks.length <= 105",
23
+ "0 <= processorTime[i] <= 109",
24
+ "1 <= tasks[i] <= 109",
25
+ "tasks.length == 4 * n"
26
+ ],
27
+ "python_template": "class Solution(object):\n def minProcessingTime(self, processorTime, tasks):\n \"\"\"\n :type processorTime: List[int]\n :type tasks: List[int]\n :rtype: int\n \"\"\"\n ",
28
+ "java_template": "class Solution {\n public int minProcessingTime(List<Integer> processorTime, List<Integer> tasks) {\n \n }\n}",
29
+ "metadata": {
30
+ "func_name": "minProcessingTime"
31
+ }
32
+ }
minimum-recolors-to-get-k-consecutive-black-blocks.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2463,
3
+ "name": "minimum-recolors-to-get-k-consecutive-black-blocks",
4
+ "difficulty": "Easy",
5
+ "link": "https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks/",
6
+ "date": "2022-08-06",
7
+ "task_description": "You are given a **0-indexed** string `blocks` of length `n`, where `blocks[i]` is either `'W'` or `'B'`, representing the color of the `ith` block. The characters `'W'` and `'B'` denote the colors white and black, respectively. You are also given an integer `k`, which is the desired number of **consecutive** black blocks. In one operation, you can **recolor** a white block such that it becomes a black block. Return_ the **minimum** number of operations needed such that there is at least **one** occurrence of _`k`_ consecutive black blocks._ **Example 1:** ``` **Input:** blocks = \"WBBWWBBWBW\", k = 7 **Output:** 3 **Explanation:** One way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks so that blocks = \"BBBBBBBWBW\". It can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations. Therefore, we return 3. ``` **Example 2:** ``` **Input:** blocks = \"WBWBBBW\", k = 2 **Output:** 0 **Explanation:** No changes need to be made, since 2 consecutive black blocks already exist. Therefore, we return 0. ``` **Constraints:** `n == blocks.length` `1 <= n <= 100` `blocks[i]` is either `'W'` or `'B'`. `1 <= k <= n`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "blocks = \"WBBWWBBWBW\", k = 7",
12
+ "output": "3 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "blocks = \"WBWBBBW\", k = 2",
17
+ "output": "0 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "n == blocks.length",
22
+ "1 <= n <= 100",
23
+ "blocks[i] is either 'W' or 'B'.",
24
+ "1 <= k <= n"
25
+ ],
26
+ "python_template": "class Solution(object):\n def minimumRecolors(self, blocks, k):\n \"\"\"\n :type blocks: str\n :type k: int\n :rtype: int\n \"\"\"\n ",
27
+ "java_template": "class Solution {\n public int minimumRecolors(String blocks, int k) {\n \n }\n}",
28
+ "metadata": {
29
+ "func_name": "minimumRecolors"
30
+ }
31
+ }
minimum-replacements-to-sort-the-array.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2450,
3
+ "name": "minimum-replacements-to-sort-the-array",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-replacements-to-sort-the-array/",
6
+ "date": "2022-07-23",
7
+ "task_description": "You are given a **0-indexed** integer array `nums`. In one operation you can replace any element of the array with **any two** elements that **sum** to it. For example, consider `nums = [5,6,7]`. In one operation, we can replace `nums[1]` with `2` and `4` and convert `nums` to `[5,2,4,7]`. Return _the minimum number of operations to make an array that is sorted in **non-decreasing** order_. **Example 1:** ``` **Input:** nums = [3,9,3] **Output:** 2 **Explanation:** Here are the steps to sort the array in non-decreasing order: - From [3,9,3], replace the 9 with 3 and 6 so the array becomes [3,3,6,3] - From [3,3,6,3], replace the 6 with 3 and 3 so the array becomes [3,3,3,3,3] There are 2 steps to sort the array in non-decreasing order. Therefore, we return 2. ``` **Example 2:** ``` **Input:** nums = [1,2,3,4,5] **Output:** 0 **Explanation:** The array is already in non-decreasing order. Therefore, we return 0. ``` **Constraints:** `1 <= nums.length <= 105` `1 <= nums[i] <= 109`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [3,9,3]",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [1,2,3,4,5]",
17
+ "output": "0 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "For example, consider nums = [5,6,7]. In one operation, we can replace nums[1] with 2 and 4 and convert nums to [5,2,4,7].",
22
+ "1 <= nums.length <= 105",
23
+ "1 <= nums[i] <= 109"
24
+ ],
25
+ "python_template": "class Solution(object):\n def minimumReplacement(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
26
+ "java_template": "class Solution {\n public long minimumReplacement(int[] nums) {\n \n }\n}",
27
+ "metadata": {
28
+ "func_name": "minimumReplacement"
29
+ }
30
+ }
minimum-reverse-operations.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2726,
3
+ "name": "minimum-reverse-operations",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-reverse-operations/",
6
+ "date": "2023-03-26",
7
+ "task_description": "You are given an integer `n` and an integer `p` representing an array `arr` of length `n` where all elements are set to 0's, except position `p` which is set to 1. You are also given an integer array `banned` containing restricted positions. Perform the following operation on `arr`: Reverse a **subarray** with size `k` if the single 1 is not set to a position in `banned`. Return an integer array `answer` with `n` results where the `ith` result is_ _the **minimum** number of operations needed to bring the single 1 to position `i` in `arr`, or -1 if it is impossible. **Example 1:** **Input:** n = 4, p = 0, banned = [1,2], k = 4 **Output:** [0,-1,-1,1] **Explanation:** Initially 1 is placed at position 0 so the number of operations we need for position 0 is 0. We can never place 1 on the banned positions, so the answer for positions 1 and 2 is -1. Perform the operation of size 4 to reverse the whole array. After a single operation 1 is at position 3 so the answer for position 3 is 1. **Example 2:** **Input:** n = 5, p = 0, banned = [2,4], k = 3 **Output:** [0,-1,-1,-1,-1] **Explanation:** Initially 1 is placed at position 0 so the number of operations we need for position 0 is 0. We cannot perform the operation on the subarray positions `[0, 2]` because position 2 is in banned. Because 1 cannot be set at position 2, it is impossible to set 1 at other positions in more operations. **Example 3:** **Input:** n = 4, p = 2, banned = [0,1,3], k = 1 **Output:** [-1,-1,0,-1] **Explanation:** Perform operations of size 1 and 1 never changes its position. **Constraints:** `1 <= n <= 105` `0 <= p <= n - 1` `0 <= banned.length <= n - 1` `0 <= banned[i] <= n - 1` `1 <= k <= n ` `banned[i] != p` all values in `banned` are **unique**",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "n = 4, p = 0, banned = [1,2], k = 4",
12
+ "output": "[0,-1,-1,1] "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "n = 5, p = 0, banned = [2,4], k = 3",
17
+ "output": "[0,-1,-1,-1,-1] "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "n = 4, p = 2, banned = [0,1,3], k = 1",
22
+ "output": "[-1,-1,0,-1] "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "Reverse a subarray with size k if the single 1 is not set to a position in banned.",
27
+ "Initially 1 is placed at position 0 so the number of operations we need for position 0 is 0.",
28
+ "We can never place 1 on the banned positions, so the answer for positions 1 and 2 is -1.",
29
+ "Perform the operation of size 4 to reverse the whole array.",
30
+ "After a single operation 1 is at position 3 so the answer for position 3 is 1.",
31
+ "Initially 1 is placed at position 0 so the number of operations we need for position 0 is 0.",
32
+ "We cannot perform the operation on the subarray positions [0, 2] because position 2 is in banned.",
33
+ "Because 1 cannot be set at position 2, it is impossible to set 1 at other positions in more operations.",
34
+ "1 <= n <= 105",
35
+ "0 <= p <= n - 1",
36
+ "0 <= banned.length <= n - 1",
37
+ "0 <= banned[i] <= n - 1",
38
+ "1 <= k <= n",
39
+ "banned[i] != p",
40
+ "all values in banned are unique"
41
+ ],
42
+ "python_template": "class Solution(object):\n def minReverseOperations(self, n, p, banned, k):\n \"\"\"\n :type n: int\n :type p: int\n :type banned: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"\n ",
43
+ "java_template": "class Solution {\n public int[] minReverseOperations(int n, int p, int[] banned, int k) {\n \n }\n}",
44
+ "metadata": {
45
+ "func_name": "minReverseOperations"
46
+ }
47
+ }
minimum-right-shifts-to-sort-the-array.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3045,
3
+ "name": "minimum-right-shifts-to-sort-the-array",
4
+ "difficulty": "Easy",
5
+ "link": "https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array/",
6
+ "date": "2023-09-02",
7
+ "task_description": "You are given a **0-indexed** array `nums` of length `n` containing **distinct** positive integers. Return _the **minimum** number of **right shifts** required to sort _`nums`_ and _`-1`_ if this is not possible._ A **right shift** is defined as shifting the element at index `i` to index `(i + 1) % n`, for all indices. **Example 1:** ``` **Input:** nums = [3,4,5,1,2] **Output:** 2 **Explanation:** After the first right shift, nums = [2,3,4,5,1]. After the second right shift, nums = [1,2,3,4,5]. Now nums is sorted; therefore the answer is 2. ``` **Example 2:** ``` **Input:** nums = [1,3,5] **Output:** 0 **Explanation:** nums is already sorted therefore, the answer is 0. ``` **Example 3:** ``` **Input:** nums = [2,1,4] **Output:** -1 **Explanation:** It's impossible to sort the array using right shifts. ``` **Constraints:** `1 <= nums.length <= 100` `1 <= nums[i] <= 100` `nums` contains distinct integers.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [3,4,5,1,2]",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [1,3,5]",
17
+ "output": "0 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums = [2,1,4]",
22
+ "output": "-1 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "1 <= nums.length <= 100",
27
+ "1 <= nums[i] <= 100",
28
+ "nums contains distinct integers."
29
+ ],
30
+ "python_template": "class Solution(object):\n def minimumRightShifts(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
31
+ "java_template": "class Solution {\n public int minimumRightShifts(List<Integer> nums) {\n \n }\n}",
32
+ "metadata": {
33
+ "func_name": "minimumRightShifts"
34
+ }
35
+ }
minimum-rounds-to-complete-all-tasks.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2362,
3
+ "name": "minimum-rounds-to-complete-all-tasks",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-rounds-to-complete-all-tasks/",
6
+ "date": "2022-04-10",
7
+ "task_description": "You are given a **0-indexed** integer array `tasks`, where `tasks[i]` represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the **same difficulty level**. Return _the **minimum** rounds required to complete all the tasks, or _`-1`_ if it is not possible to complete all the tasks._ **Example 1:** ``` **Input:** tasks = [2,2,3,3,2,4,4,4,4,4] **Output:** 4 **Explanation:** To complete all the tasks, a possible plan is: - In the first round, you complete 3 tasks of difficulty level 2. - In the second round, you complete 2 tasks of difficulty level 3. - In the third round, you complete 3 tasks of difficulty level 4. - In the fourth round, you complete 2 tasks of difficulty level 4. It can be shown that all the tasks cannot be completed in fewer than 4 rounds, so the answer is 4. ``` **Example 2:** ``` **Input:** tasks = [2,3,3] **Output:** -1 **Explanation:** There is only 1 task of difficulty level 2, but in each round, you can only complete either 2 or 3 tasks of the same difficulty level. Hence, you cannot complete all the tasks, and the answer is -1. ``` **Constraints:** `1 <= tasks.length <= 105` `1 <= tasks[i] <= 109` **Note:** This question is the same as 2870: Minimum Number of Operations to Make Array Empty.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "tasks = [2,2,3,3,2,4,4,4,4,4]",
12
+ "output": "4 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "tasks = [2,3,3]",
17
+ "output": "-1 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "1 <= tasks.length <= 105",
22
+ "1 <= tasks[i] <= 109"
23
+ ],
24
+ "python_template": "class Solution(object):\n def minimumRounds(self, tasks):\n \"\"\"\n :type tasks: List[int]\n :rtype: int\n \"\"\"\n ",
25
+ "java_template": "class Solution {\n public int minimumRounds(int[] tasks) {\n \n }\n}",
26
+ "metadata": {
27
+ "func_name": "minimumRounds"
28
+ }
29
+ }
minimum-score-after-removals-on-a-tree.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2400,
3
+ "name": "minimum-score-after-removals-on-a-tree",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-score-after-removals-on-a-tree/",
6
+ "date": "2022-06-19",
7
+ "task_description": "There is an undirected connected tree with `n` nodes labeled from `0` to `n - 1` and `n - 1` edges. You are given a **0-indexed** integer array `nums` of length `n` where `nums[i]` represents the value of the `ith` node. You are also given a 2D integer array `edges` of length `n - 1` where `edges[i] = [ai, bi]` indicates that there is an edge between nodes `ai` and `bi` in the tree. Remove two **distinct** edges of the tree to form three connected components. For a pair of removed edges, the following steps are defined: Get the XOR of all the values of the nodes for **each** of the three components respectively. The **difference** between the **largest** XOR value and the **smallest** XOR value is the **score** of the pair. For example, say the three components have the node values: `[4,5,7]`, `[1,9]`, and `[3,3,3]`. The three XOR values are `4 ^ 5 ^ 7 = **6**`, `1 ^ 9 = **8**`, and `3 ^ 3 ^ 3 = **3**`. The largest XOR value is `8` and the smallest XOR value is `3`. The score is then `8 - 3 = 5`. Return _the **minimum** score of any possible pair of edge removals on the given tree_. **Example 1:** ``` **Input:** nums = [1,5,5,4,11], edges = [[0,1],[1,2],[1,3],[3,4]] **Output:** 9 **Explanation:** The diagram above shows a way to make a pair of removals. - The 1st component has nodes [1,3,4] with values [5,4,11]. Its XOR value is 5 ^ 4 ^ 11 = 10. - The 2nd component has node [0] with value [1]. Its XOR value is 1 = 1. - The 3rd component has node [2] with value [5]. Its XOR value is 5 = 5. The score is the difference between the largest and smallest XOR value which is 10 - 1 = 9. It can be shown that no other pair of removals will obtain a smaller score than 9. ``` **Example 2:** ``` **Input:** nums = [5,5,2,4,4,2], edges = [[0,1],[1,2],[5,2],[4,3],[1,3]] **Output:** 0 **Explanation:** The diagram above shows a way to make a pair of removals. - The 1st component has nodes [3,4] with values [4,4]. Its XOR value is 4 ^ 4 = 0. - The 2nd component has nodes [1,0] with values [5,5]. Its XOR value is 5 ^ 5 = 0. - The 3rd component has nodes [2,5] with values [2,2]. Its XOR value is 2 ^ 2 = 0. The score is the difference between the largest and smallest XOR value which is 0 - 0 = 0. We cannot obtain a smaller score than 0. ``` **Constraints:** `n == nums.length` `3 <= n <= 1000` `1 <= nums[i] <= 108` `edges.length == n - 1` `edges[i].length == 2` `0 <= ai, bi < n` `ai != bi` `edges` represents a valid tree.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [1,5,5,4,11], edges = [[0,1],[1,2],[1,3],[3,4]]",
12
+ "output": "9 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [5,5,2,4,4,2], edges = [[0,1],[1,2],[5,2],[4,3],[1,3]]",
17
+ "output": "0 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "For example, say the three components have the node values: [4,5,7], [1,9], and [3,3,3]. The three XOR values are 4 ^ 5 ^ 7 = 6, 1 ^ 9 = 8, and 3 ^ 3 ^ 3 = 3. The largest XOR value is 8 and the smallest XOR value is 3. The score is then 8 - 3 = 5.",
22
+ "n == nums.length",
23
+ "3 <= n <= 1000",
24
+ "1 <= nums[i] <= 108",
25
+ "edges.length == n - 1",
26
+ "edges[i].length == 2",
27
+ "0 <= ai, bi < n",
28
+ "ai != bi",
29
+ "edges represents a valid tree."
30
+ ],
31
+ "python_template": "class Solution(object):\n def minimumScore(self, nums, edges):\n \"\"\"\n :type nums: List[int]\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"\n ",
32
+ "java_template": "class Solution {\n public int minimumScore(int[] nums, int[][] edges) {\n \n }\n}",
33
+ "metadata": {
34
+ "func_name": "minimumScore"
35
+ }
36
+ }
minimum-score-by-changing-two-elements.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2706,
3
+ "name": "minimum-score-by-changing-two-elements",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-score-by-changing-two-elements/",
6
+ "date": "2023-02-04",
7
+ "task_description": "You are given an integer array `nums`. The **low** score of `nums` is the **minimum** absolute difference between any two integers. The **high** score of `nums` is the **maximum** absolute difference between any two integers. The **score** of `nums` is the sum of the **high** and **low** scores. Return the **minimum score** after **changing two elements** of `nums`. **Example 1:** **Input:** nums = [1,4,7,8,5] **Output:** 3 **Explanation:** Change `nums[0]` and `nums[1]` to be 6 so that `nums` becomes [6,6,7,8,5]. The low score is the minimum absolute difference: |6 - 6| = 0. The high score is the maximum absolute difference: |8 - 5| = 3. The sum of high and low score is 3. **Example 2:** **Input:** nums = [1,4,3] **Output:** 0 **Explanation:** Change `nums[1]` and `nums[2]` to 1 so that `nums` becomes [1,1,1]. The sum of maximum absolute difference and minimum absolute difference is 0. **Constraints:** `3 <= nums.length <= 105` `1 <= nums[i] <= 109`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [1,4,7,8,5]",
12
+ "output": "3 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [1,4,3]",
17
+ "output": "0 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "The low score of nums is the minimum absolute difference between any two integers.",
22
+ "The high score of nums is the maximum absolute difference between any two integers.",
23
+ "The score of nums is the sum of the high and low scores.",
24
+ "Change nums[0] and nums[1] to be 6 so that nums becomes [6,6,7,8,5].",
25
+ "The low score is the minimum absolute difference: |6 - 6| = 0.",
26
+ "The high score is the maximum absolute difference: |8 - 5| = 3.",
27
+ "The sum of high and low score is 3.",
28
+ "Change nums[1] and nums[2] to 1 so that nums becomes [1,1,1].",
29
+ "The sum of maximum absolute difference and minimum absolute difference is 0.",
30
+ "3 <= nums.length <= 105",
31
+ "1 <= nums[i] <= 109"
32
+ ],
33
+ "python_template": "class Solution(object):\n def minimizeSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
34
+ "java_template": "class Solution {\n public int minimizeSum(int[] nums) {\n \n }\n}",
35
+ "metadata": {
36
+ "func_name": "minimizeSum"
37
+ }
38
+ }
minimum-score-of-a-path-between-two-cities.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2582,
3
+ "name": "minimum-score-of-a-path-between-two-cities",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities/",
6
+ "date": "2022-11-27",
7
+ "task_description": "You are given a positive integer `n` representing `n` cities numbered from `1` to `n`. You are also given a **2D** array `roads` where `roads[i] = [ai, bi, distancei]` indicates that there is a **bidirectional **road between cities `ai` and `bi` with a distance equal to `distancei`. The cities graph is not necessarily connected. The **score** of a path between two cities is defined as the **minimum **distance of a road in this path. Return _the **minimum **possible score of a path between cities _`1`_ and _`n`. **Note**: A path is a sequence of roads between two cities. It is allowed for a path to contain the same road **multiple** times, and you can visit cities `1` and `n` multiple times along the path. The test cases are generated such that there is **at least** one path between `1` and `n`. **Example 1:** ``` **Input:** n = 4, roads = [[1,2,9],[2,3,6],[2,4,5],[1,4,7]] **Output:** 5 **Explanation:** The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 4. The score of this path is min(9,5) = 5. It can be shown that no other path has less score. ``` **Example 2:** ``` **Input:** n = 4, roads = [[1,2,2],[1,3,4],[3,4,7]] **Output:** 2 **Explanation:** The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 1 -> 3 -> 4. The score of this path is min(2,2,4,7) = 2. ``` **Constraints:** `2 <= n <= 105` `1 <= roads.length <= 105` `roads[i].length == 3` `1 <= ai, bi <= n` `ai != bi` `1 <= distancei <= 104` There are no repeated edges. There is at least one path between `1` and `n`.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "n = 4, roads = [[1,2,9],[2,3,6],[2,4,5],[1,4,7]]",
12
+ "output": "5 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "n = 4, roads = [[1,2,2],[1,3,4],[3,4,7]]",
17
+ "output": "2 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "A path is a sequence of roads between two cities.",
22
+ "It is allowed for a path to contain the same road multiple times, and you can visit cities 1 and n multiple times along the path.",
23
+ "The test cases are generated such that there is at least one path between 1 and n.",
24
+ "2 <= n <= 105",
25
+ "1 <= roads.length <= 105",
26
+ "roads[i].length == 3",
27
+ "1 <= ai, bi <= n",
28
+ "ai != bi",
29
+ "1 <= distancei <= 104",
30
+ "There are no repeated edges.",
31
+ "There is at least one path between 1 and n."
32
+ ],
33
+ "python_template": "class Solution(object):\n def minScore(self, n, roads):\n \"\"\"\n :type n: int\n :type roads: List[List[int]]\n :rtype: int\n \"\"\"\n ",
34
+ "java_template": "class Solution {\n public int minScore(int n, int[][] roads) {\n \n }\n}",
35
+ "metadata": {
36
+ "func_name": "minScore"
37
+ }
38
+ }
minimum-seconds-to-equalize-a-circular-array.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2920,
3
+ "name": "minimum-seconds-to-equalize-a-circular-array",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-seconds-to-equalize-a-circular-array/",
6
+ "date": "2023-07-22",
7
+ "task_description": "You are given a **0-indexed** array `nums` containing `n` integers. At each second, you perform the following operation on the array: For every index `i` in the range `[0, n - 1]`, replace `nums[i]` with either `nums[i]`, `nums[(i - 1 + n) % n]`, or `nums[(i + 1) % n]`. **Note** that all the elements get replaced simultaneously. Return _the **minimum** number of seconds needed to make all elements in the array_ `nums` _equal_. **Example 1:** ``` **Input:** nums = [1,2,1,2] **Output:** 1 **Explanation:** We can equalize the array in 1 second in the following way: - At 1st second, replace values at each index with [nums[3],nums[1],nums[3],nums[3]]. After replacement, nums = [2,2,2,2]. It can be proven that 1 second is the minimum amount of seconds needed for equalizing the array. ``` **Example 2:** ``` **Input:** nums = [2,1,3,3,2] **Output:** 2 **Explanation:** We can equalize the array in 2 seconds in the following way: - At 1st second, replace values at each index with [nums[0],nums[2],nums[2],nums[2],nums[3]]. After replacement, nums = [2,3,3,3,3]. - At 2nd second, replace values at each index with [nums[1],nums[1],nums[2],nums[3],nums[4]]. After replacement, nums = [3,3,3,3,3]. It can be proven that 2 seconds is the minimum amount of seconds needed for equalizing the array. ``` **Example 3:** ``` **Input:** nums = [5,5,5,5] **Output:** 0 **Explanation:** We don't need to perform any operations as all elements in the initial array are the same. ``` **Constraints:** `1 <= n == nums.length <= 105` `1 <= nums[i] <= 109`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [1,2,1,2]",
12
+ "output": "1 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [2,1,3,3,2]",
17
+ "output": "2 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums = [5,5,5,5]",
22
+ "output": "0 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "For every index i in the range [0, n - 1], replace nums[i] with either nums[i], nums[(i - 1 + n) % n], or nums[(i + 1) % n].",
27
+ "1 <= n == nums.length <= 105",
28
+ "1 <= nums[i] <= 109"
29
+ ],
30
+ "python_template": "class Solution(object):\n def minimumSeconds(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
31
+ "java_template": "class Solution {\n public int minimumSeconds(List<Integer> nums) {\n \n }\n}",
32
+ "metadata": {
33
+ "func_name": "minimumSeconds"
34
+ }
35
+ }
minimum-size-subarray-in-infinite-array.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3141,
3
+ "name": "minimum-size-subarray-in-infinite-array",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-size-subarray-in-infinite-array/",
6
+ "date": "2023-09-24",
7
+ "task_description": "You are given a **0-indexed** array `nums` and an integer `target`. A **0-indexed** array `infinite_nums` is generated by infinitely appending the elements of `nums` to itself. Return _the length of the **shortest** subarray of the array _`infinite_nums`_ with a sum equal to _`target`_._ If there is no such subarray return `-1`. **Example 1:** ``` **Input:** nums = [1,2,3], target = 5 **Output:** 2 **Explanation:** In this example infinite_nums = [1,2,3,1,2,3,1,2,...]. The subarray in the range [1,2], has the sum equal to target = 5 and length = 2. It can be proven that 2 is the shortest length of a subarray with sum equal to target = 5. ``` **Example 2:** ``` **Input:** nums = [1,1,1,2,3], target = 4 **Output:** 2 **Explanation:** In this example infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...]. The subarray in the range [4,5], has the sum equal to target = 4 and length = 2. It can be proven that 2 is the shortest length of a subarray with sum equal to target = 4. ``` **Example 3:** ``` **Input:** nums = [2,4,6,8], target = 3 **Output:** -1 **Explanation:** In this example infinite_nums = [2,4,6,8,2,4,6,8,...]. It can be proven that there is no subarray with sum equal to target = 3. ``` **Constraints:** `1 <= nums.length <= 105` `1 <= nums[i] <= 105` `1 <= target <= 109`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [1,2,3], target = 5",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [1,1,1,2,3], target = 4",
17
+ "output": "2 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums = [2,4,6,8], target = 3",
22
+ "output": "-1 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "1 <= nums.length <= 105",
27
+ "1 <= nums[i] <= 105",
28
+ "1 <= target <= 109"
29
+ ],
30
+ "python_template": "class Solution(object):\n def minSizeSubarray(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"\n ",
31
+ "java_template": "class Solution {\n public int minSizeSubarray(int[] nums, int target) {\n \n }\n}",
32
+ "metadata": {
33
+ "func_name": "minSizeSubarray"
34
+ }
35
+ }
minimum-string-length-after-removing-substrings.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2800,
3
+ "name": "minimum-string-length-after-removing-substrings",
4
+ "difficulty": "Easy",
5
+ "link": "https://leetcode.com/problems/minimum-string-length-after-removing-substrings/",
6
+ "date": "2023-05-14",
7
+ "task_description": "You are given a string `s` consisting only of **uppercase** English letters. You can apply some operations to this string where, in one operation, you can remove **any** occurrence of one of the substrings `\"AB\"` or `\"CD\"` from `s`. Return _the **minimum** possible length of the resulting string that you can obtain_. **Note** that the string concatenates after removing the substring and could produce new `\"AB\"` or `\"CD\"` substrings. **Example 1:** ``` **Input:** s = \"ABFCACDB\" **Output:** 2 **Explanation:** We can do the following operations: - Remove the substring \"ABFCACDB\", so s = \"FCACDB\". - Remove the substring \"FCACDB\", so s = \"FCAB\". - Remove the substring \"FCAB\", so s = \"FC\". So the resulting length of the string is 2. It can be shown that it is the minimum length that we can obtain. ``` **Example 2:** ``` **Input:** s = \"ACBBD\" **Output:** 5 **Explanation:** We cannot do any operations on the string so the length remains the same. ``` **Constraints:** `1 <= s.length <= 100` `s` consists only of uppercase English letters.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "s = \"ABFCACDB\"",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "s = \"ACBBD\"",
17
+ "output": "5 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "1 <= s.length <= 100",
22
+ "s consists only of uppercase English letters."
23
+ ],
24
+ "python_template": "class Solution(object):\n def minLength(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n ",
25
+ "java_template": "class Solution {\n public int minLength(String s) {\n \n }\n}",
26
+ "metadata": {
27
+ "func_name": "minLength"
28
+ }
29
+ }
minimum-substring-partition-of-equal-character-frequency.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3403,
3
+ "name": "minimum-substring-partition-of-equal-character-frequency",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-substring-partition-of-equal-character-frequency/",
6
+ "date": "2024-04-27",
7
+ "task_description": "Given a string `s`, you need to partition it into one or more **balanced** substrings. For example, if `s == \"ababcc\"` then `(\"abab\", \"c\", \"c\")`, `(\"ab\", \"abc\", \"c\")`, and `(\"ababcc\")` are all valid partitions, but `(\"a\", **\"bab\"**, \"cc\")`, `(**\"aba\"**, \"bc\", \"c\")`, and `(\"ab\", **\"abcc\"**)` are not. The unbalanced substrings are bolded. Return the **minimum** number of substrings that you can partition `s` into. **Note:** A **balanced** string is a string where each character in the string occurs the same number of times. **Example 1:** **Input:** s = \"fabccddg\" **Output:** 3 **Explanation:** We can partition the string `s` into 3 substrings in one of the following ways: `(\"fab, \"ccdd\", \"g\")`, or `(\"fabc\", \"cd\", \"dg\")`. **Example 2:** **Input:** s = \"abababaccddb\" **Output:** 2 **Explanation:** We can partition the string `s` into 2 substrings like so: `(\"abab\", \"abaccddb\")`. **Constraints:** `1 <= s.length <= 1000` `s` consists only of English lowercase letters.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "s = \"fabccddg\"",
12
+ "output": "3 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "s = \"abababaccddb\"",
17
+ "output": "2 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "1 <= s.length <= 1000",
22
+ "s consists only of English lowercase letters."
23
+ ],
24
+ "python_template": "class Solution(object):\n def minimumSubstringsInPartition(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n ",
25
+ "java_template": "class Solution {\n public int minimumSubstringsInPartition(String s) {\n \n }\n}",
26
+ "metadata": {
27
+ "func_name": "minimumSubstringsInPartition"
28
+ }
29
+ }
minimum-sum-of-mountain-triplets-i.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3176,
3
+ "name": "minimum-sum-of-mountain-triplets-i",
4
+ "difficulty": "Easy",
5
+ "link": "https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i/",
6
+ "date": "2023-10-15",
7
+ "task_description": "You are given a **0-indexed** array `nums` of integers. A triplet of indices `(i, j, k)` is a **mountain** if: `i < j < k` `nums[i] < nums[j]` and `nums[k] < nums[j]` Return _the **minimum possible sum** of a mountain triplet of_ `nums`. _If no such triplet exists, return_ `-1`. **Example 1:** ``` **Input:** nums = [8,6,1,5,3] **Output:** 9 **Explanation:** Triplet (2, 3, 4) is a mountain triplet of sum 9 since: - 2 < 3 < 4 - nums[2] < nums[3] and nums[4] < nums[3] And the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9. ``` **Example 2:** ``` **Input:** nums = [5,4,8,7,10,2] **Output:** 13 **Explanation:** Triplet (1, 3, 5) is a mountain triplet of sum 13 since: - 1 < 3 < 5 - nums[1] < nums[3] and nums[5] < nums[3] And the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13. ``` **Example 3:** ``` **Input:** nums = [6,5,4,3,4,5] **Output:** -1 **Explanation:** It can be shown that there are no mountain triplets in nums. ``` **Constraints:** `3 <= nums.length <= 50` `1 <= nums[i] <= 50`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [8,6,1,5,3]",
12
+ "output": "9 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [5,4,8,7,10,2]",
17
+ "output": "13 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums = [6,5,4,3,4,5]",
22
+ "output": "-1 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "i < j < k",
27
+ "nums[i] < nums[j] and nums[k] < nums[j]",
28
+ "3 <= nums.length <= 50",
29
+ "1 <= nums[i] <= 50"
30
+ ],
31
+ "python_template": "class Solution(object):\n def minimumSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
32
+ "java_template": "class Solution {\n public int minimumSum(int[] nums) {\n \n }\n}",
33
+ "metadata": {
34
+ "func_name": "minimumSum"
35
+ }
36
+ }
minimum-sum-of-mountain-triplets-ii.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3186,
3
+ "name": "minimum-sum-of-mountain-triplets-ii",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-sum-of-mountain-triplets-ii/",
6
+ "date": "2023-10-15",
7
+ "task_description": "You are given a **0-indexed** array `nums` of integers. A triplet of indices `(i, j, k)` is a **mountain** if: `i < j < k` `nums[i] < nums[j]` and `nums[k] < nums[j]` Return _the **minimum possible sum** of a mountain triplet of_ `nums`. _If no such triplet exists, return_ `-1`. **Example 1:** ``` **Input:** nums = [8,6,1,5,3] **Output:** 9 **Explanation:** Triplet (2, 3, 4) is a mountain triplet of sum 9 since: - 2 < 3 < 4 - nums[2] < nums[3] and nums[4] < nums[3] And the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9. ``` **Example 2:** ``` **Input:** nums = [5,4,8,7,10,2] **Output:** 13 **Explanation:** Triplet (1, 3, 5) is a mountain triplet of sum 13 since: - 1 < 3 < 5 - nums[1] < nums[3] and nums[5] < nums[3] And the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13. ``` **Example 3:** ``` **Input:** nums = [6,5,4,3,4,5] **Output:** -1 **Explanation:** It can be shown that there are no mountain triplets in nums. ``` **Constraints:** `3 <= nums.length <= 105` `1 <= nums[i] <= 108`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [8,6,1,5,3]",
12
+ "output": "9 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [5,4,8,7,10,2]",
17
+ "output": "13 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums = [6,5,4,3,4,5]",
22
+ "output": "-1 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "i < j < k",
27
+ "nums[i] < nums[j] and nums[k] < nums[j]",
28
+ "3 <= nums.length <= 105",
29
+ "1 <= nums[i] <= 108"
30
+ ],
31
+ "python_template": "class Solution(object):\n def minimumSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
32
+ "java_template": "class Solution {\n public int minimumSum(int[] nums) {\n \n }\n}",
33
+ "metadata": {
34
+ "func_name": "minimumSum"
35
+ }
36
+ }
minimum-sum-of-squared-difference.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2418,
3
+ "name": "minimum-sum-of-squared-difference",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-sum-of-squared-difference/",
6
+ "date": "2022-06-25",
7
+ "task_description": "You are given two positive **0-indexed** integer arrays `nums1` and `nums2`, both of length `n`. The **sum of squared difference** of arrays `nums1` and `nums2` is defined as the **sum** of `(nums1[i] - nums2[i])2` for each `0 <= i < n`. You are also given two positive integers `k1` and `k2`. You can modify any of the elements of `nums1` by `+1` or `-1` at most `k1` times. Similarly, you can modify any of the elements of `nums2` by `+1` or `-1` at most `k2` times. Return _the minimum **sum of squared difference** after modifying array _`nums1`_ at most _`k1`_ times and modifying array _`nums2`_ at most _`k2`_ times_. **Note**: You are allowed to modify the array elements to become **negative** integers. **Example 1:** ``` **Input:** nums1 = [1,2,3,4], nums2 = [2,10,20,19], k1 = 0, k2 = 0 **Output:** 579 **Explanation:** The elements in nums1 and nums2 cannot be modified because k1 = 0 and k2 = 0. The sum of square difference will be: (1 - 2)2 + (2 - 10)2 + (3 - 20)2 + (4 - 19)2 = 579. ``` **Example 2:** ``` **Input:** nums1 = [1,4,10,12], nums2 = [5,8,6,9], k1 = 1, k2 = 1 **Output:** 43 **Explanation:** One way to obtain the minimum sum of square difference is: - Increase nums1[0] once. - Increase nums2[2] once. The minimum of the sum of square difference will be: (2 - 5)2 + (4 - 8)2 + (10 - 7)2 + (12 - 9)2 = 43. Note that, there are other ways to obtain the minimum of the sum of square difference, but there is no way to obtain a sum smaller than 43. ``` **Constraints:** `n == nums1.length == nums2.length` `1 <= n <= 105` `0 <= nums1[i], nums2[i] <= 105` `0 <= k1, k2 <= 109`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums1 = [1,2,3,4], nums2 = [2,10,20,19], k1 = 0, k2 = 0",
12
+ "output": "579 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums1 = [1,4,10,12], nums2 = [5,8,6,9], k1 = 1, k2 = 1",
17
+ "output": "43 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "n == nums1.length == nums2.length",
22
+ "1 <= n <= 105",
23
+ "0 <= nums1[i], nums2[i] <= 105",
24
+ "0 <= k1, k2 <= 109"
25
+ ],
26
+ "python_template": "class Solution(object):\n def minSumSquareDiff(self, nums1, nums2, k1, k2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :type k1: int\n :type k2: int\n :rtype: int\n \"\"\"\n ",
27
+ "java_template": "class Solution {\n public long minSumSquareDiff(int[] nums1, int[] nums2, int k1, int k2) {\n \n }\n}",
28
+ "metadata": {
29
+ "func_name": "minSumSquareDiff"
30
+ }
31
+ }
minimum-sum-of-values-by-dividing-array.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3364,
3
+ "name": "minimum-sum-of-values-by-dividing-array",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-sum-of-values-by-dividing-array/",
6
+ "date": "2024-04-07",
7
+ "task_description": "You are given two arrays `nums` and `andValues` of length `n` and `m` respectively. The **value** of an array is equal to the **last** element of that array. You have to divide `nums` into `m` **disjoint contiguous** subarrays such that for the `ith` subarray `[li, ri]`, the bitwise `AND` of the subarray elements is equal to `andValues[i]`, in other words, `nums[li] & nums[li + 1] & ... & nums[ri] == andValues[i]` for all `1 <= i <= m`, where `&` represents the bitwise `AND` operator. Return _the **minimum** possible sum of the **values** of the _`m`_ subarrays _`nums`_ is divided into_. _If it is not possible to divide _`nums`_ into _`m`_ subarrays satisfying these conditions, return_ `-1`. **Example 1:** **Input:** nums = [1,4,3,3,2], andValues = [0,3,3,2] **Output:** 12 **Explanation:** The only possible way to divide `nums` is: `[1,4]` as `1 & 4 == 0`. `[3]` as the bitwise `AND` of a single element subarray is that element itself. `[3]` as the bitwise `AND` of a single element subarray is that element itself. `[2]` as the bitwise `AND` of a single element subarray is that element itself. The sum of the values for these subarrays is `4 + 3 + 3 + 2 = 12`. **Example 2:** **Input:** nums = [2,3,5,7,7,7,5], andValues = [0,7,5] **Output:** 17 **Explanation:** There are three ways to divide `nums`: `[[2,3,5],[7,7,7],[5]]` with the sum of the values `5 + 7 + 5 == 17`. `[[2,3,5,7],[7,7],[5]]` with the sum of the values `7 + 7 + 5 == 19`. `[[2,3,5,7,7],[7],[5]]` with the sum of the values `7 + 7 + 5 == 19`. The minimum possible sum of the values is `17`. **Example 3:** **Input:** nums = [1,2,3,4], andValues = [2] **Output:** -1 **Explanation:** The bitwise `AND` of the entire array `nums` is `0`. As there is no possible way to divide `nums` into a single subarray to have the bitwise `AND` of elements `2`, return `-1`. **Constraints:** `1 <= n == nums.length <= 104` `1 <= m == andValues.length <= min(n, 10)` `1 <= nums[i] < 105` `0 <= andValues[j] < 105`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [1,4,3,3,2], andValues = [0,3,3,2]",
12
+ "output": "12 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [2,3,5,7,7,7,5], andValues = [0,7,5]",
17
+ "output": "17 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums = [1,2,3,4], andValues = [2]",
22
+ "output": "-1 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "1 <= n == nums.length <= 104",
27
+ "1 <= m == andValues.length <= min(n, 10)",
28
+ "1 <= nums[i] < 105",
29
+ "0 <= andValues[j] < 105"
30
+ ],
31
+ "python_template": "class Solution(object):\n def minimumValueSum(self, nums, andValues):\n \"\"\"\n :type nums: List[int]\n :type andValues: List[int]\n :rtype: int\n \"\"\"\n ",
32
+ "java_template": "class Solution {\n public int minimumValueSum(int[] nums, int[] andValues) {\n \n }\n}",
33
+ "metadata": {
34
+ "func_name": "minimumValueSum"
35
+ }
36
+ }
minimum-swaps-to-group-all-1s-together-ii.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2255,
3
+ "name": "minimum-swaps-to-group-all-1s-together-ii",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together-ii/",
6
+ "date": "2022-01-02",
7
+ "task_description": "A **swap** is defined as taking two **distinct** positions in an array and swapping the values in them. A **circular** array is defined as an array where we consider the **first** element and the **last** element to be **adjacent**. Given a **binary** **circular** array `nums`, return _the minimum number of swaps required to group all _`1`_'s present in the array together at **any location**_. **Example 1:** ``` **Input:** nums = [0,1,0,1,1,0,0] **Output:** 1 **Explanation:** Here are a few of the ways to group all the 1's together: [0,0,1,1,1,0,0] using 1 swap. [0,1,1,1,0,0,0] using 1 swap. [1,1,0,0,0,0,1] using 2 swaps (using the circular property of the array). There is no way to group all 1's together with 0 swaps. Thus, the minimum number of swaps required is 1. ``` **Example 2:** ``` **Input:** nums = [0,1,1,1,0,0,1,1,0] **Output:** 2 **Explanation:** Here are a few of the ways to group all the 1's together: [1,1,1,0,0,0,0,1,1] using 2 swaps (using the circular property of the array). [1,1,1,1,1,0,0,0,0] using 2 swaps. There is no way to group all 1's together with 0 or 1 swaps. Thus, the minimum number of swaps required is 2. ``` **Example 3:** ``` **Input:** nums = [1,1,0,0,1] **Output:** 0 **Explanation:** All the 1's are already grouped together due to the circular property of the array. Thus, the minimum number of swaps required is 0. ``` **Constraints:** `1 <= nums.length <= 105` `nums[i]` is either `0` or `1`.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [0,1,0,1,1,0,0]",
12
+ "output": "1 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [0,1,1,1,0,0,1,1,0]",
17
+ "output": "2 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums = [1,1,0,0,1]",
22
+ "output": "0 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "1 <= nums.length <= 105",
27
+ "nums[i] is either 0 or 1."
28
+ ],
29
+ "python_template": "class Solution(object):\n def minSwaps(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
30
+ "java_template": "class Solution {\n public int minSwaps(int[] nums) {\n \n }\n}",
31
+ "metadata": {
32
+ "func_name": "minSwaps"
33
+ }
34
+ }
minimum-time-to-break-locks-i.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3649,
3
+ "name": "minimum-time-to-break-locks-i",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-time-to-break-locks-i/",
6
+ "date": "2024-11-23",
7
+ "task_description": "Bob is stuck in a dungeon and must break `n` locks, each requiring some amount of **energy** to break. The required energy for each lock is stored in an array called `strength` where `strength[i]` indicates the energy needed to break the `ith` lock. To break a lock, Bob uses a sword with the following characteristics: The initial energy of the sword is 0. The initial factor `x` by which the energy of the sword increases is 1. Every minute, the energy of the sword increases by the current factor `x`. To break the `ith` lock, the energy of the sword must reach **at least** `strength[i]`. After breaking a lock, the energy of the sword resets to 0, and the factor `x` increases by a given value `k`. Your task is to determine the **minimum** time in minutes required for Bob to break all `n` locks and escape the dungeon. Return the **minimum **time required for Bob to break all `n` locks. **Example 1:** **Input:** strength = [3,4,1], k = 1 **Output:** 4 **Explanation:** Time Energy x Action Updated x 0 0 1 Nothing 1 1 1 1 Break 3rd Lock 2 2 2 2 Nothing 2 3 4 2 Break 2nd Lock 3 4 3 3 Break 1st Lock 3 The locks cannot be broken in less than 4 minutes; thus, the answer is 4. **Example 2:** **Input:** strength = [2,5,4], k = 2 **Output:** 5 **Explanation:** Time Energy x Action Updated x 0 0 1 Nothing 1 1 1 1 Nothing 1 2 2 1 Break 1st Lock 3 3 3 3 Nothing 3 4 6 3 Break 2nd Lock 5 5 5 5 Break 3rd Lock 7 The locks cannot be broken in less than 5 minutes; thus, the answer is 5. **Constraints:** `n == strength.length` `1 <= n <= 8` `1 <= K <= 10` `1 <= strength[i] <= 106`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "strength = [3,4,1], k = 1",
12
+ "output": "4 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "strength = [2,5,4], k = 2",
17
+ "output": "5 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "The initial energy of the sword is 0.",
22
+ "The initial factor x by which the energy of the sword increases is 1.",
23
+ "Every minute, the energy of the sword increases by the current factor x.",
24
+ "To break the ith lock, the energy of the sword must reach at least strength[i].",
25
+ "After breaking a lock, the energy of the sword resets to 0, and the factor x increases by a given value k.",
26
+ "n == strength.length",
27
+ "1 <= n <= 8",
28
+ "1 <= K <= 10",
29
+ "1 <= strength[i] <= 106"
30
+ ],
31
+ "python_template": "class Solution(object):\n def findMinimumTime(self, strength, k):\n \"\"\"\n :type strength: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n ",
32
+ "java_template": "class Solution {\n public int findMinimumTime(List<Integer> strength, int k) {\n \n }\n}",
33
+ "metadata": {
34
+ "func_name": "findMinimumTime"
35
+ }
36
+ }
minimum-time-to-complete-all-tasks.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2657,
3
+ "name": "minimum-time-to-complete-all-tasks",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-time-to-complete-all-tasks/",
6
+ "date": "2023-03-05",
7
+ "task_description": "There is a computer that can run an unlimited number of tasks **at the same time**. You are given a 2D integer array `tasks` where `tasks[i] = [starti, endi, durationi]` indicates that the `ith` task should run for a total of `durationi` seconds (not necessarily continuous) within the **inclusive** time range `[starti, endi]`. You may turn on the computer only when it needs to run a task. You can also turn it off if it is idle. Return _the minimum time during which the computer should be turned on to complete all tasks_. **Example 1:** ``` **Input:** tasks = [[2,3,1],[4,5,1],[1,5,2]] **Output:** 2 **Explanation:** - The first task can be run in the inclusive time range [2, 2]. - The second task can be run in the inclusive time range [5, 5]. - The third task can be run in the two inclusive time ranges [2, 2] and [5, 5]. The computer will be on for a total of 2 seconds. ``` **Example 2:** ``` **Input:** tasks = [[1,3,2],[2,5,3],[5,6,2]] **Output:** 4 **Explanation:** - The first task can be run in the inclusive time range [2, 3]. - The second task can be run in the inclusive time ranges [2, 3] and [5, 5]. - The third task can be run in the two inclusive time range [5, 6]. The computer will be on for a total of 4 seconds. ``` **Constraints:** `1 <= tasks.length <= 2000` `tasks[i].length == 3` `1 <= starti, endi <= 2000` `1 <= durationi <= endi - starti + 1 `",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "tasks = [[2,3,1],[4,5,1],[1,5,2]]",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "tasks = [[1,3,2],[2,5,3],[5,6,2]]",
17
+ "output": "4 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "1 <= tasks.length <= 2000",
22
+ "tasks[i].length == 3",
23
+ "1 <= starti, endi <= 2000",
24
+ "1 <= durationi <= endi - starti + 1"
25
+ ],
26
+ "python_template": "class Solution(object):\n def findMinimumTime(self, tasks):\n \"\"\"\n :type tasks: List[List[int]]\n :rtype: int\n \"\"\"\n ",
27
+ "java_template": "class Solution {\n public int findMinimumTime(int[][] tasks) {\n \n }\n}",
28
+ "metadata": {
29
+ "func_name": "findMinimumTime"
30
+ }
31
+ }
minimum-time-to-complete-trips.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2294,
3
+ "name": "minimum-time-to-complete-trips",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-time-to-complete-trips/",
6
+ "date": "2022-02-20",
7
+ "task_description": "You are given an array `time` where `time[i]` denotes the time taken by the `ith` bus to complete **one trip**. Each bus can make multiple trips **successively**; that is, the next trip can start **immediately after** completing the current trip. Also, each bus operates **independently**; that is, the trips of one bus do not influence the trips of any other bus. You are also given an integer `totalTrips`, which denotes the number of trips all buses should make **in total**. Return _the **minimum time** required for all buses to complete **at least** _`totalTrips`_ trips_. **Example 1:** ``` **Input:** time = [1,2,3], totalTrips = 5 **Output:** 3 **Explanation:** - At time t = 1, the number of trips completed by each bus are [1,0,0]. The total number of trips completed is 1 + 0 + 0 = 1. - At time t = 2, the number of trips completed by each bus are [2,1,0]. The total number of trips completed is 2 + 1 + 0 = 3. - At time t = 3, the number of trips completed by each bus are [3,1,1]. The total number of trips completed is 3 + 1 + 1 = 5. So the minimum time needed for all buses to complete at least 5 trips is 3. ``` **Example 2:** ``` **Input:** time = [2], totalTrips = 1 **Output:** 2 **Explanation:** There is only one bus, and it will complete its first trip at t = 2. So the minimum time needed to complete 1 trip is 2. ``` **Constraints:** `1 <= time.length <= 105` `1 <= time[i], totalTrips <= 107`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "time = [1,2,3], totalTrips = 5",
12
+ "output": "3 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "time = [2], totalTrips = 1",
17
+ "output": "2 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "1 <= time.length <= 105",
22
+ "1 <= time[i], totalTrips <= 107"
23
+ ],
24
+ "python_template": "class Solution(object):\n def minimumTime(self, time, totalTrips):\n \"\"\"\n :type time: List[int]\n :type totalTrips: int\n :rtype: int\n \"\"\"\n ",
25
+ "java_template": "class Solution {\n public long minimumTime(int[] time, int totalTrips) {\n \n }\n}",
26
+ "metadata": {
27
+ "func_name": "minimumTime"
28
+ }
29
+ }
minimum-time-to-make-array-sum-at-most-x.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2952,
3
+ "name": "minimum-time-to-make-array-sum-at-most-x",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-time-to-make-array-sum-at-most-x/",
6
+ "date": "2023-07-22",
7
+ "task_description": "You are given two **0-indexed** integer arrays `nums1` and `nums2` of equal length. Every second, for all indices `0 <= i < nums1.length`, value of `nums1[i]` is incremented by `nums2[i]`. **After** this is done, you can do the following operation: Choose an index `0 <= i < nums1.length` and make `nums1[i] = 0`. You are also given an integer `x`. Return _the **minimum** time in which you can make the sum of all elements of _`nums1`_ to be** less than or equal** to _`x`, _or _`-1`_ if this is not possible._ **Example 1:** ``` **Input:** nums1 = [1,2,3], nums2 = [1,2,3], x = 4 **Output:** 3 **Explanation:** For the 1st second, we apply the operation on i = 0. Therefore nums1 = [0,2+2,3+3] = [0,4,6]. For the 2nd second, we apply the operation on i = 1. Therefore nums1 = [0+1,0,6+3] = [1,0,9]. For the 3rd second, we apply the operation on i = 2. Therefore nums1 = [1+1,0+2,0] = [2,2,0]. Now sum of nums1 = 4. It can be shown that these operations are optimal, so we return 3. ``` **Example 2:** ``` **Input:** nums1 = [1,2,3], nums2 = [3,3,3], x = 4 **Output:** -1 **Explanation:** It can be shown that the sum of nums1 will always be greater than x, no matter which operations are performed. ``` **Constraints:** `1 <= nums1.length <= 103` `1 <= nums1[i] <= 103` `0 <= nums2[i] <= 103` `nums1.length == nums2.length` `0 <= x <= 106`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums1 = [1,2,3], nums2 = [1,2,3], x = 4",
12
+ "output": "3 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums1 = [1,2,3], nums2 = [3,3,3], x = 4",
17
+ "output": "-1 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "Choose an index 0 <= i < nums1.length and make nums1[i] = 0.",
22
+ "1 <= nums1.length <= 103",
23
+ "1 <= nums1[i] <= 103",
24
+ "0 <= nums2[i] <= 103",
25
+ "nums1.length == nums2.length",
26
+ "0 <= x <= 106"
27
+ ],
28
+ "python_template": "class Solution(object):\n def minimumTime(self, nums1, nums2, x):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :type x: int\n :rtype: int\n \"\"\"\n ",
29
+ "java_template": "class Solution {\n public int minimumTime(List<Integer> nums1, List<Integer> nums2, int x) {\n \n }\n}",
30
+ "metadata": {
31
+ "func_name": "minimumTime"
32
+ }
33
+ }
minimum-time-to-remove-all-cars-containing-illegal-goods.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2286,
3
+ "name": "minimum-time-to-remove-all-cars-containing-illegal-goods",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-time-to-remove-all-cars-containing-illegal-goods/",
6
+ "date": "2022-01-30",
7
+ "task_description": "You are given a **0-indexed** binary string `s` which represents a sequence of train cars. `s[i] = '0'` denotes that the `ith` car does **not** contain illegal goods and `s[i] = '1'` denotes that the `ith` car does contain illegal goods. As the train conductor, you would like to get rid of all the cars containing illegal goods. You can do any of the following three operations **any** number of times: Remove a train car from the **left** end (i.e., remove `s[0]`) which takes 1 unit of time. Remove a train car from the **right** end (i.e., remove `s[s.length - 1]`) which takes 1 unit of time. Remove a train car from **anywhere** in the sequence which takes 2 units of time. Return _the **minimum** time to remove all the cars containing illegal goods_. Note that an empty sequence of cars is considered to have no cars containing illegal goods. **Example 1:** ``` **Input:** s = \"**11**00**1**0**1**\" **Output:** 5 **Explanation:** One way to remove all the cars containing illegal goods from the sequence is to - remove a car from the left end 2 times. Time taken is 2 * 1 = 2. - remove a car from the right end. Time taken is 1. - remove the car containing illegal goods found in the middle. Time taken is 2. This obtains a total time of 2 + 1 + 2 = 5. An alternative way is to - remove a car from the left end 2 times. Time taken is 2 * 1 = 2. - remove a car from the right end 3 times. Time taken is 3 * 1 = 3. This also obtains a total time of 2 + 3 = 5. 5 is the minimum time taken to remove all the cars containing illegal goods. There are no other ways to remove them with less time. ``` **Example 2:** ``` **Input:** s = \"00**1**0\" **Output:** 2 **Explanation:** One way to remove all the cars containing illegal goods from the sequence is to - remove a car from the left end 3 times. Time taken is 3 * 1 = 3. This obtains a total time of 3. Another way to remove all the cars containing illegal goods from the sequence is to - remove the car containing illegal goods found in the middle. Time taken is 2. This obtains a total time of 2. Another way to remove all the cars containing illegal goods from the sequence is to - remove a car from the right end 2 times. Time taken is 2 * 1 = 2. This obtains a total time of 2. 2 is the minimum time taken to remove all the cars containing illegal goods. There are no other ways to remove them with less time. ``` **Constraints:** `1 <= s.length <= 2 * 105` `s[i]` is either `'0'` or `'1'`.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "s = \" 11 00 1 0 1 \"",
12
+ "output": "5 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "s = \"00 1 0\"",
17
+ "output": "2 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "1 <= s.length <= 2 * 105",
22
+ "s[i] is either '0' or '1'."
23
+ ],
24
+ "python_template": "class Solution(object):\n def minimumTime(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n ",
25
+ "java_template": "class Solution {\n public int minimumTime(String s) {\n \n }\n}",
26
+ "metadata": {
27
+ "func_name": "minimumTime"
28
+ }
29
+ }
minimum-time-to-repair-cars.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2665,
3
+ "name": "minimum-time-to-repair-cars",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-time-to-repair-cars/",
6
+ "date": "2023-03-04",
7
+ "task_description": "You are given an integer array `ranks` representing the **ranks** of some mechanics. ranksi is the rank of the ith mechanic. A mechanic with a rank `r` can repair n cars in `r * n2` minutes. You are also given an integer `cars` representing the total number of cars waiting in the garage to be repaired. Return _the **minimum** time taken to repair all the cars._ **Note:** All the mechanics can repair the cars simultaneously. **Example 1:** ``` **Input:** ranks = [4,2,3,1], cars = 10 **Output:** 16 **Explanation:** - The first mechanic will repair two cars. The time required is 4 * 2 * 2 = 16 minutes. - The second mechanic will repair two cars. The time required is 2 * 2 * 2 = 8 minutes. - The third mechanic will repair two cars. The time required is 3 * 2 * 2 = 12 minutes. - The fourth mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes. It can be proved that the cars cannot be repaired in less than 16 minutes.​​​​​ ``` **Example 2:** ``` **Input:** ranks = [5,1,8], cars = 6 **Output:** 16 **Explanation:** - The first mechanic will repair one car. The time required is 5 * 1 * 1 = 5 minutes. - The second mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes. - The third mechanic will repair one car. The time required is 8 * 1 * 1 = 8 minutes. It can be proved that the cars cannot be repaired in less than 16 minutes.​​​​​ ``` **Constraints:** `1 <= ranks.length <= 105` `1 <= ranks[i] <= 100` `1 <= cars <= 106`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "ranks = [4,2,3,1], cars = 10",
12
+ "output": "16 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "ranks = [5,1,8], cars = 6",
17
+ "output": "16 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "1 <= ranks.length <= 105",
22
+ "1 <= ranks[i] <= 100",
23
+ "1 <= cars <= 106"
24
+ ],
25
+ "python_template": "class Solution(object):\n def repairCars(self, ranks, cars):\n \"\"\"\n :type ranks: List[int]\n :type cars: int\n :rtype: int\n \"\"\"\n ",
26
+ "java_template": "class Solution {\n public long repairCars(int[] ranks, int cars) {\n \n }\n}",
27
+ "metadata": {
28
+ "func_name": "repairCars"
29
+ }
30
+ }
minimum-time-to-revert-word-to-initial-state-i.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3297,
3
+ "name": "minimum-time-to-revert-word-to-initial-state-i",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-time-to-revert-word-to-initial-state-i/",
6
+ "date": "2024-01-28",
7
+ "task_description": "You are given a **0-indexed** string `word` and an integer `k`. At every second, you must perform the following operations: Remove the first `k` characters of `word`. Add any `k` characters to the end of `word`. **Note** that you do not necessarily need to add the same characters that you removed. However, you must perform **both** operations at every second. Return _the **minimum** time greater than zero required for_ `word` _to revert to its **initial** state_. **Example 1:** ``` **Input:** word = \"abacaba\", k = 3 **Output:** 2 **Explanation:** At the 1st second, we remove characters \"aba\" from the prefix of word, and add characters \"bac\" to the end of word. Thus, word becomes equal to \"cababac\". At the 2nd second, we remove characters \"cab\" from the prefix of word, and add \"aba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state. It can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state. ``` **Example 2:** ``` **Input:** word = \"abacaba\", k = 4 **Output:** 1 **Explanation:** At the 1st second, we remove characters \"abac\" from the prefix of word, and add characters \"caba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state. It can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state. ``` **Example 3:** ``` **Input:** word = \"abcbabcd\", k = 2 **Output:** 4 **Explanation:** At every second, we will remove the first 2 characters of word, and add the same characters to the end of word. After 4 seconds, word becomes equal to \"abcbabcd\" and reverts to its initial state. It can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state. ``` **Constraints:** `1 <= word.length <= 50 ` `1 <= k <= word.length` `word` consists only of lowercase English letters.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "word = \"abacaba\", k = 3",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "word = \"abacaba\", k = 4",
17
+ "output": "1 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "word = \"abcbabcd\", k = 2",
22
+ "output": "4 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "Remove the first k characters of word.",
27
+ "Add any k characters to the end of word.",
28
+ "1 <= word.length <= 50",
29
+ "1 <= k <= word.length",
30
+ "word consists only of lowercase English letters."
31
+ ],
32
+ "python_template": "class Solution(object):\n def minimumTimeToInitialState(self, word, k):\n \"\"\"\n :type word: str\n :type k: int\n :rtype: int\n \"\"\"\n ",
33
+ "java_template": "class Solution {\n public int minimumTimeToInitialState(String word, int k) {\n \n }\n}",
34
+ "metadata": {
35
+ "func_name": "minimumTimeToInitialState"
36
+ }
37
+ }
minimum-time-to-revert-word-to-initial-state-ii.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3296,
3
+ "name": "minimum-time-to-revert-word-to-initial-state-ii",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-time-to-revert-word-to-initial-state-ii/",
6
+ "date": "2024-01-28",
7
+ "task_description": "You are given a **0-indexed** string `word` and an integer `k`. At every second, you must perform the following operations: Remove the first `k` characters of `word`. Add any `k` characters to the end of `word`. **Note** that you do not necessarily need to add the same characters that you removed. However, you must perform **both** operations at every second. Return _the **minimum** time greater than zero required for_ `word` _to revert to its **initial** state_. **Example 1:** ``` **Input:** word = \"abacaba\", k = 3 **Output:** 2 **Explanation:** At the 1st second, we remove characters \"aba\" from the prefix of word, and add characters \"bac\" to the end of word. Thus, word becomes equal to \"cababac\". At the 2nd second, we remove characters \"cab\" from the prefix of word, and add \"aba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state. It can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state. ``` **Example 2:** ``` **Input:** word = \"abacaba\", k = 4 **Output:** 1 **Explanation:** At the 1st second, we remove characters \"abac\" from the prefix of word, and add characters \"caba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state. It can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state. ``` **Example 3:** ``` **Input:** word = \"abcbabcd\", k = 2 **Output:** 4 **Explanation:** At every second, we will remove the first 2 characters of word, and add the same characters to the end of word. After 4 seconds, word becomes equal to \"abcbabcd\" and reverts to its initial state. It can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state. ``` **Constraints:** `1 <= word.length <= 106` `1 <= k <= word.length` `word` consists only of lowercase English letters.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "word = \"abacaba\", k = 3",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "word = \"abacaba\", k = 4",
17
+ "output": "1 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "word = \"abcbabcd\", k = 2",
22
+ "output": "4 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "Remove the first k characters of word.",
27
+ "Add any k characters to the end of word.",
28
+ "1 <= word.length <= 106",
29
+ "1 <= k <= word.length",
30
+ "word consists only of lowercase English letters."
31
+ ],
32
+ "python_template": "class Solution(object):\n def minimumTimeToInitialState(self, word, k):\n \"\"\"\n :type word: str\n :type k: int\n :rtype: int\n \"\"\"\n ",
33
+ "java_template": "class Solution {\n public int minimumTimeToInitialState(String word, int k) {\n \n }\n}",
34
+ "metadata": {
35
+ "func_name": "minimumTimeToInitialState"
36
+ }
37
+ }
minimum-time-to-visit-disappearing-nodes.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3389,
3
+ "name": "minimum-time-to-visit-disappearing-nodes",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/minimum-time-to-visit-disappearing-nodes/",
6
+ "date": "2024-03-30",
7
+ "task_description": "There is an undirected graph of `n` nodes. You are given a 2D array `edges`, where `edges[i] = [ui, vi, lengthi]` describes an edge between node `ui` and node `vi` with a traversal time of `lengthi` units. Additionally, you are given an array `disappear`, where `disappear[i]` denotes the time when the node `i` disappears from the graph and you won't be able to visit it. **Note** that the graph might be _disconnected_ and might contain _multiple edges_. Return the array `answer`, with `answer[i]` denoting the **minimum** units of time required to reach node `i` from node 0. If node `i` is **unreachable** from node 0 then `answer[i]` is `-1`. **Example 1:** **Input:** n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,1,5] **Output:** [0,-1,4] **Explanation:** We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears. For node 0, we don't need any time as it is our starting point. For node 1, we need at least 2 units of time to traverse `edges[0]`. Unfortunately, it disappears at that moment, so we won't be able to visit it. For node 2, we need at least 4 units of time to traverse `edges[2]`. **Example 2:** **Input:** n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,3,5] **Output:** [0,2,3] **Explanation:** We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears. For node 0, we don't need any time as it is the starting point. For node 1, we need at least 2 units of time to traverse `edges[0]`. For node 2, we need at least 3 units of time to traverse `edges[0]` and `edges[1]`. **Example 3:** **Input:** n = 2, edges = [[0,1,1]], disappear = [1,1] **Output:** [0,-1] **Explanation:** Exactly when we reach node 1, it disappears. **Constraints:** `1 <= n <= 5 * 104` `0 <= edges.length <= 105` `edges[i] == [ui, vi, lengthi]` `0 <= ui, vi <= n - 1` `1 <= lengthi <= 105` `disappear.length == n` `1 <= disappear[i] <= 105`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,1,5]",
12
+ "output": "[0,-1,4] "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,3,5]",
17
+ "output": "[0,2,3] "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "n = 2, edges = [[0,1,1]], disappear = [1,1]",
22
+ "output": "[0,-1] "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "For node 0, we don't need any time as it is our starting point.",
27
+ "For node 1, we need at least 2 units of time to traverse edges[0]. Unfortunately, it disappears at that moment, so we won't be able to visit it.",
28
+ "For node 2, we need at least 4 units of time to traverse edges[2].",
29
+ "For node 0, we don't need any time as it is the starting point.",
30
+ "For node 1, we need at least 2 units of time to traverse edges[0].",
31
+ "For node 2, we need at least 3 units of time to traverse edges[0] and edges[1].",
32
+ "1 <= n <= 5 * 104",
33
+ "0 <= edges.length <= 105",
34
+ "edges[i] == [ui, vi, lengthi]",
35
+ "0 <= ui, vi <= n - 1",
36
+ "1 <= lengthi <= 105",
37
+ "disappear.length == n",
38
+ "1 <= disappear[i] <= 105"
39
+ ],
40
+ "python_template": "class Solution(object):\n def minimumTime(self, n, edges, disappear):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type disappear: List[int]\n :rtype: List[int]\n \"\"\"\n ",
41
+ "java_template": "class Solution {\n public int[] minimumTime(int n, int[][] edges, int[] disappear) {\n \n }\n}",
42
+ "metadata": {
43
+ "func_name": "minimumTime"
44
+ }
45
+ }
minimum-total-cost-to-make-arrays-unequal.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2592,
3
+ "name": "minimum-total-cost-to-make-arrays-unequal",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-total-cost-to-make-arrays-unequal/",
6
+ "date": "2022-11-26",
7
+ "task_description": "You are given two **0-indexed** integer arrays `nums1` and `nums2`, of equal length `n`. In one operation, you can swap the values of any two indices of `nums1`. The **cost** of this operation is the **sum** of the indices. Find the **minimum** total cost of performing the given operation **any** number of times such that `nums1[i] != nums2[i]` for all `0 <= i <= n - 1` after performing all the operations. Return _the **minimum total cost** such that _`nums1` and `nums2`_ satisfy the above condition_. In case it is not possible, return `-1`. **Example 1:** ``` **Input:** nums1 = [1,2,3,4,5], nums2 = [1,2,3,4,5] **Output:** 10 **Explanation:** One of the ways we can perform the operations is: - Swap values at indices 0 and 3, incurring cost = 0 + 3 = 3. Now, nums1 = [4,2,3,1,5] - Swap values at indices 1 and 2, incurring cost = 1 + 2 = 3. Now, nums1 = [4,3,2,1,5]. - Swap values at indices 0 and 4, incurring cost = 0 + 4 = 4. Now, nums1 =[5,3,2,1,4]. We can see that for each index i, nums1[i] != nums2[i]. The cost required here is 10. Note that there are other ways to swap values, but it can be proven that it is not possible to obtain a cost less than 10. ``` **Example 2:** ``` **Input:** nums1 = [2,2,2,1,3], nums2 = [1,2,2,3,3] **Output:** 10 **Explanation:** One of the ways we can perform the operations is: - Swap values at indices 2 and 3, incurring cost = 2 + 3 = 5. Now, nums1 = [2,2,1,2,3]. - Swap values at indices 1 and 4, incurring cost = 1 + 4 = 5. Now, nums1 = [2,3,1,2,2]. The total cost needed here is 10, which is the minimum possible. ``` **Example 3:** ``` **Input:** nums1 = [1,2,2], nums2 = [1,2,2] **Output:** -1 **Explanation:** It can be shown that it is not possible to satisfy the given conditions irrespective of the number of operations we perform. Hence, we return -1. ``` **Constraints:** `n == nums1.length == nums2.length` `1 <= n <= 105` `1 <= nums1[i], nums2[i] <= n`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums1 = [1,2,3,4,5], nums2 = [1,2,3,4,5]",
12
+ "output": "10 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums1 = [2,2,2,1,3], nums2 = [1,2,2,3,3]",
17
+ "output": "10 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums1 = [1,2,2], nums2 = [1,2,2]",
22
+ "output": "-1 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "n == nums1.length == nums2.length",
27
+ "1 <= n <= 105",
28
+ "1 <= nums1[i], nums2[i] <= n"
29
+ ],
30
+ "python_template": "class Solution(object):\n def minimumTotalCost(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"\n ",
31
+ "java_template": "class Solution {\n public long minimumTotalCost(int[] nums1, int[] nums2) {\n \n }\n}",
32
+ "metadata": {
33
+ "func_name": "minimumTotalCost"
34
+ }
35
+ }
minimum-total-distance-traveled.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2554,
3
+ "name": "minimum-total-distance-traveled",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-total-distance-traveled/",
6
+ "date": "2022-10-30",
7
+ "task_description": "There are some robots and factories on the X-axis. You are given an integer array `robot` where `robot[i]` is the position of the `ith` robot. You are also given a 2D integer array `factory` where `factory[j] = [positionj, limitj]` indicates that `positionj` is the position of the `jth` factory and that the `jth` factory can repair at most `limitj` robots. The positions of each robot are **unique**. The positions of each factory are also **unique**. Note that a robot can be **in the same position** as a factory initially. All the robots are initially broken; they keep moving in one direction. The direction could be the negative or the positive direction of the X-axis. When a robot reaches a factory that did not reach its limit, the factory repairs the robot, and it stops moving. **At any moment**, you can set the initial direction of moving for **some** robot. Your target is to minimize the total distance traveled by all the robots. Return _the minimum total distance traveled by all the robots_. The test cases are generated such that all the robots can be repaired. **Note that** All robots move at the same speed. If two robots move in the same direction, they will never collide. If two robots move in opposite directions and they meet at some point, they do not collide. They cross each other. If a robot passes by a factory that reached its limits, it crosses it as if it does not exist. If the robot moved from a position `x` to a position `y`, the distance it moved is `|y - x|`. **Example 1:** ``` **Input:** robot = [0,4,6], factory = [[2,2],[6,2]] **Output:** 4 **Explanation:** As shown in the figure: - The first robot at position 0 moves in the positive direction. It will be repaired at the first factory. - The second robot at position 4 moves in the negative direction. It will be repaired at the first factory. - The third robot at position 6 will be repaired at the second factory. It does not need to move. The limit of the first factory is 2, and it fixed 2 robots. The limit of the second factory is 2, and it fixed 1 robot. The total distance is |2 - 0| + |2 - 4| + |6 - 6| = 4. It can be shown that we cannot achieve a better total distance than 4. ``` **Example 2:** ``` **Input:** robot = [1,-1], factory = [[-2,1],[2,1]] **Output:** 2 **Explanation:** As shown in the figure: - The first robot at position 1 moves in the positive direction. It will be repaired at the second factory. - The second robot at position -1 moves in the negative direction. It will be repaired at the first factory. The limit of the first factory is 1, and it fixed 1 robot. The limit of the second factory is 1, and it fixed 1 robot. The total distance is |2 - 1| + |(-2) - (-1)| = 2. It can be shown that we cannot achieve a better total distance than 2. ``` **Constraints:** `1 <= robot.length, factory.length <= 100` `factory[j].length == 2` `-109 <= robot[i], positionj <= 109` `0 <= limitj <= robot.length` The input will be generated such that it is always possible to repair every robot.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "robot = [0,4,6], factory = [[2,2],[6,2]]",
12
+ "output": "4 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "robot = [1,-1], factory = [[-2,1],[2,1]]",
17
+ "output": "2 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "All robots move at the same speed.",
22
+ "If two robots move in the same direction, they will never collide.",
23
+ "If two robots move in opposite directions and they meet at some point, they do not collide. They cross each other.",
24
+ "If a robot passes by a factory that reached its limits, it crosses it as if it does not exist.",
25
+ "If the robot moved from a position x to a position y, the distance it moved is |y - x|.",
26
+ "1 <= robot.length, factory.length <= 100",
27
+ "factory[j].length == 2",
28
+ "-109 <= robot[i], positionj <= 109",
29
+ "0 <= limitj <= robot.length",
30
+ "The input will be generated such that it is always possible to repair every robot."
31
+ ],
32
+ "python_template": "class Solution(object):\n def minimumTotalDistance(self, robot, factory):\n \"\"\"\n :type robot: List[int]\n :type factory: List[List[int]]\n :rtype: int\n \"\"\"\n ",
33
+ "java_template": "class Solution {\n public long minimumTotalDistance(List<Integer> robot, int[][] factory) {\n \n }\n}",
34
+ "metadata": {
35
+ "func_name": "minimumTotalDistance"
36
+ }
37
+ }
minimum-weighted-subgraph-with-the-required-paths.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2321,
3
+ "name": "minimum-weighted-subgraph-with-the-required-paths",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-weighted-subgraph-with-the-required-paths/",
6
+ "date": "2022-03-06",
7
+ "task_description": "You are given an integer `n` denoting the number of nodes of a **weighted directed** graph. The nodes are numbered from `0` to `n - 1`. You are also given a 2D integer array `edges` where `edges[i] = [fromi, toi, weighti]` denotes that there exists a **directed** edge from `fromi` to `toi` with weight `weighti`. Lastly, you are given three **distinct** integers `src1`, `src2`, and `dest` denoting three distinct nodes of the graph. Return _the **minimum weight** of a subgraph of the graph such that it is **possible** to reach_ `dest` _from both_ `src1` _and_ `src2` _via a set of edges of this subgraph_. In case such a subgraph does not exist, return `-1`. A **subgraph** is a graph whose vertices and edges are subsets of the original graph. The **weight** of a subgraph is the sum of weights of its constituent edges. **Example 1:** ``` **Input:** n = 6, edges = [[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]], src1 = 0, src2 = 1, dest = 5 **Output:** 9 **Explanation:** The above figure represents the input graph. The blue edges represent one of the subgraphs that yield the optimal answer. Note that the subgraph [[1,0,3],[0,5,6]] also yields the optimal answer. It is not possible to get a subgraph with less weight satisfying all the constraints. ``` **Example 2:** ``` **Input:** n = 3, edges = [[0,1,1],[2,1,1]], src1 = 0, src2 = 1, dest = 2 **Output:** -1 **Explanation:** The above figure represents the input graph. It can be seen that there does not exist any path from node 1 to node 2, hence there are no subgraphs satisfying all the constraints. ``` **Constraints:** `3 <= n <= 105` `0 <= edges.length <= 105` `edges[i].length == 3` `0 <= fromi, toi, src1, src2, dest <= n - 1` `fromi != toi` `src1`, `src2`, and `dest` are pairwise distinct. `1 <= weight[i] <= 105`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "n = 6, edges = [[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]], src1 = 0, src2 = 1, dest = 5",
12
+ "output": "9 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "n = 3, edges = [[0,1,1],[2,1,1]], src1 = 0, src2 = 1, dest = 2",
17
+ "output": "-1 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "3 <= n <= 105",
22
+ "0 <= edges.length <= 105",
23
+ "edges[i].length == 3",
24
+ "0 <= fromi, toi, src1, src2, dest <= n - 1",
25
+ "fromi != toi",
26
+ "src1, src2, and dest are pairwise distinct.",
27
+ "1 <= weight[i] <= 105"
28
+ ],
29
+ "python_template": "class Solution(object):\n def minimumWeight(self, n, edges, src1, src2, dest):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type src1: int\n :type src2: int\n :type dest: int\n :rtype: int\n \"\"\"\n ",
30
+ "java_template": "class Solution {\n public long minimumWeight(int n, int[][] edges, int src1, int src2, int dest) {\n \n }\n}",
31
+ "metadata": {
32
+ "func_name": "minimumWeight"
33
+ }
34
+ }
minimum-white-tiles-after-covering-with-carpets.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2311,
3
+ "name": "minimum-white-tiles-after-covering-with-carpets",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/minimum-white-tiles-after-covering-with-carpets/",
6
+ "date": "2022-03-05",
7
+ "task_description": "You are given a **0-indexed binary** string `floor`, which represents the colors of tiles on a floor: `floor[i] = '0'` denotes that the `ith` tile of the floor is colored **black**. On the other hand, `floor[i] = '1'` denotes that the `ith` tile of the floor is colored **white**. You are also given `numCarpets` and `carpetLen`. You have `numCarpets` **black** carpets, each of length `carpetLen` tiles. Cover the tiles with the given carpets such that the number of **white** tiles still visible is **minimum**. Carpets may overlap one another. Return _the **minimum** number of white tiles still visible._ **Example 1:** ``` **Input:** floor = \"10110101\", numCarpets = 2, carpetLen = 2 **Output:** 2 **Explanation:** The figure above shows one way of covering the tiles with the carpets such that only 2 white tiles are visible. No other way of covering the tiles with the carpets can leave less than 2 white tiles visible. ``` **Example 2:** ``` **Input:** floor = \"11111\", numCarpets = 2, carpetLen = 3 **Output:** 0 **Explanation:** The figure above shows one way of covering the tiles with the carpets such that no white tiles are visible. Note that the carpets are able to overlap one another. ``` **Constraints:** `1 <= carpetLen <= floor.length <= 1000` `floor[i]` is either `'0'` or `'1'`. `1 <= numCarpets <= 1000`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "floor = \"10110101\", numCarpets = 2, carpetLen = 2",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "floor = \"11111\", numCarpets = 2, carpetLen = 3",
17
+ "output": "0 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "floor[i] = '0' denotes that the ith tile of the floor is colored black.",
22
+ "On the other hand, floor[i] = '1' denotes that the ith tile of the floor is colored white.",
23
+ "1 <= carpetLen <= floor.length <= 1000",
24
+ "floor[i] is either '0' or '1'.",
25
+ "1 <= numCarpets <= 1000"
26
+ ],
27
+ "python_template": "class Solution(object):\n def minimumWhiteTiles(self, floor, numCarpets, carpetLen):\n \"\"\"\n :type floor: str\n :type numCarpets: int\n :type carpetLen: int\n :rtype: int\n \"\"\"\n ",
28
+ "java_template": "class Solution {\n public int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) {\n \n }\n}",
29
+ "metadata": {
30
+ "func_name": "minimumWhiteTiles"
31
+ }
32
+ }
modify-graph-edge-weights.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2803,
3
+ "name": "modify-graph-edge-weights",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/modify-graph-edge-weights/",
6
+ "date": "2023-05-14",
7
+ "task_description": "You are given an **undirected weighted** **connected** graph containing `n` nodes labeled from `0` to `n - 1`, and an integer array `edges` where `edges[i] = [ai, bi, wi]` indicates that there is an edge between nodes `ai` and `bi` with weight `wi`. Some edges have a weight of `-1` (`wi = -1`), while others have a **positive** weight (`wi > 0`). Your task is to modify **all edges** with a weight of `-1` by assigning them **positive integer values **in the range `[1, 2 * 109]` so that the **shortest distance** between the nodes `source` and `destination` becomes equal to an integer `target`. If there are **multiple** **modifications** that make the shortest distance between `source` and `destination` equal to `target`, any of them will be considered correct. Return _an array containing all edges (even unmodified ones) in any order if it is possible to make the shortest distance from _`source`_ to _`destination`_ equal to _`target`_, or an **empty array** if it's impossible._ **Note:** You are not allowed to modify the weights of edges with initial positive weights. **Example 1:** **** ``` **Input:** n = 5, edges = [[4,1,-1],[2,0,-1],[0,3,-1],[4,3,-1]], source = 0, destination = 1, target = 5 **Output:** [[4,1,1],[2,0,1],[0,3,3],[4,3,1]] **Explanation:** The graph above shows a possible modification to the edges, making the distance from 0 to 1 equal to 5. ``` **Example 2:** **** ``` **Input:** n = 3, edges = [[0,1,-1],[0,2,5]], source = 0, destination = 2, target = 6 **Output:** [] **Explanation:** The graph above contains the initial edges. It is not possible to make the distance from 0 to 2 equal to 6 by modifying the edge with weight -1. So, an empty array is returned. ``` **Example 3:** **** ``` **Input:** n = 4, edges = [[1,0,4],[1,2,3],[2,3,5],[0,3,-1]], source = 0, destination = 2, target = 6 **Output:** [[1,0,4],[1,2,3],[2,3,5],[0,3,1]] **Explanation:** The graph above shows a modified graph having the shortest distance from 0 to 2 as 6. ``` **Constraints:** `1 <= n <= 100` `1 <= edges.length <= n * (n - 1) / 2` `edges[i].length == 3` `0 <= ai, bi < n` `wi = -1 `or `1 <= wi <= 107` `ai != bi` `0 <= source, destination < n` `source != destination` `1 <= target <= 109` The graph is connected, and there are no self-loops or repeated edges",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "n = 5, edges = [[4,1,-1],[2,0,-1],[0,3,-1],[4,3,-1]], source = 0, destination = 1, target = 5",
12
+ "output": "[[4,1,1],[2,0,1],[0,3,3],[4,3,1]] "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "n = 3, edges = [[0,1,-1],[0,2,5]], source = 0, destination = 2, target = 6",
17
+ "output": "[] "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "n = 4, edges = [[1,0,4],[1,2,3],[2,3,5],[0,3,-1]], source = 0, destination = 2, target = 6",
22
+ "output": "[[1,0,4],[1,2,3],[2,3,5],[0,3,1]] "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "1 <= n <= 100",
27
+ "1 <= edges.length <= n * (n - 1) / 2",
28
+ "edges[i].length == 3",
29
+ "0 <= ai, bi < n",
30
+ "wi = -1 or 1 <= wi <= 107",
31
+ "ai != bi",
32
+ "0 <= source, destination < n",
33
+ "source != destination",
34
+ "1 <= target <= 109",
35
+ "The graph is connected, and there are no self-loops or repeated edges"
36
+ ],
37
+ "python_template": "class Solution(object):\n def modifiedGraphEdges(self, n, edges, source, destination, target):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type source: int\n :type destination: int\n :type target: int\n :rtype: List[List[int]]\n \"\"\"\n ",
38
+ "java_template": "class Solution {\n public int[][] modifiedGraphEdges(int n, int[][] edges, int source, int destination, int target) {\n \n }\n}",
39
+ "metadata": {
40
+ "func_name": "modifiedGraphEdges"
41
+ }
42
+ }
modify-the-matrix.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3330,
3
+ "name": "modify-the-matrix",
4
+ "difficulty": "Easy",
5
+ "link": "https://leetcode.com/problems/modify-the-matrix/",
6
+ "date": "2024-02-04",
7
+ "task_description": "Given a **0-indexed** `m x n` integer matrix `matrix`, create a new **0-indexed** matrix called `answer`. Make `answer` equal to `matrix`, then replace each element with the value `-1` with the **maximum** element in its respective column. Return _the matrix_ `answer`. **Example 1:** ``` **Input:** matrix = [[1,2,-1],[4,-1,6],[7,8,9]] **Output:** [[1,2,9],[4,8,6],[7,8,9]] **Explanation:** The diagram above shows the elements that are changed (in blue). - We replace the value in the cell [1][1] with the maximum value in the column 1, that is 8. - We replace the value in the cell [0][2] with the maximum value in the column 2, that is 9. ``` **Example 2:** ``` **Input:** matrix = [[3,-1],[5,2]] **Output:** [[3,2],[5,2]] **Explanation:** The diagram above shows the elements that are changed (in blue). ``` **Constraints:** `m == matrix.length` `n == matrix[i].length` `2 <= m, n <= 50` `-1 <= matrix[i][j] <= 100` The input is generated such that each column contains at least one non-negative integer.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "matrix = [[1,2,-1],[4,-1,6],[7,8,9]]",
12
+ "output": "[[1,2,9],[4,8,6],[7,8,9]] "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "matrix = [[3,-1],[5,2]]",
17
+ "output": "[[3,2],[5,2]] "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "m == matrix.length",
22
+ "n == matrix[i].length",
23
+ "2 <= m, n <= 50",
24
+ "-1 <= matrix[i][j] <= 100",
25
+ "The input is generated such that each column contains at least one non-negative integer."
26
+ ],
27
+ "python_template": "class Solution(object):\n def modifiedMatrix(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"\n ",
28
+ "java_template": "class Solution {\n public int[][] modifiedMatrix(int[][] matrix) {\n \n }\n}",
29
+ "metadata": {
30
+ "func_name": "modifiedMatrix"
31
+ }
32
+ }
most-frequent-even-element.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2486,
3
+ "name": "most-frequent-even-element",
4
+ "difficulty": "Easy",
5
+ "link": "https://leetcode.com/problems/most-frequent-even-element/",
6
+ "date": "2022-09-04",
7
+ "task_description": "Given an integer array `nums`, return _the most frequent even element_. If there is a tie, return the **smallest** one. If there is no such element, return `-1`. **Example 1:** ``` **Input:** nums = [0,1,2,2,4,4,1] **Output:** 2 **Explanation:** The even elements are 0, 2, and 4. Of these, 2 and 4 appear the most. We return the smallest one, which is 2. ``` **Example 2:** ``` **Input:** nums = [4,4,4,9,2,4] **Output:** 4 **Explanation:** 4 is the even element appears the most. ``` **Example 3:** ``` **Input:** nums = [29,47,21,41,13,37,25,7] **Output:** -1 **Explanation:** There is no even element. ``` **Constraints:** `1 <= nums.length <= 2000` `0 <= nums[i] <= 105`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [0,1,2,2,4,4,1]",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [4,4,4,9,2,4]",
17
+ "output": "4 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums = [29,47,21,41,13,37,25,7]",
22
+ "output": "-1 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "1 <= nums.length <= 2000",
27
+ "0 <= nums[i] <= 105"
28
+ ],
29
+ "python_template": "class Solution(object):\n def mostFrequentEven(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
30
+ "java_template": "class Solution {\n public int mostFrequentEven(int[] nums) {\n \n }\n}",
31
+ "metadata": {
32
+ "func_name": "mostFrequentEven"
33
+ }
34
+ }
most-frequent-ids.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3363,
3
+ "name": "most-frequent-ids",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/most-frequent-ids/",
6
+ "date": "2024-03-17",
7
+ "task_description": "The problem involves tracking the frequency of IDs in a collection that changes over time. You have two integer arrays, `nums` and `freq`, of equal length `n`. Each element in `nums` represents an ID, and the corresponding element in `freq` indicates how many times that ID should be added to or removed from the collection at each step. **Addition of IDs:** If `freq[i]` is positive, it means `freq[i]` IDs with the value `nums[i]` are added to the collection at step `i`. **Removal of IDs:** If `freq[i]` is negative, it means `-freq[i]` IDs with the value `nums[i]` are removed from the collection at step `i`. Return an array `ans` of length `n`, where `ans[i]` represents the **count** of the _most frequent ID_ in the collection after the `ith` step. If the collection is empty at any step, `ans[i]` should be 0 for that step. **Example 1:** **Input:** nums = [2,3,2,1], freq = [3,2,-3,1] **Output:** [3,3,2,2] **Explanation:** After step 0, we have 3 IDs with the value of 2. So `ans[0] = 3`. After step 1, we have 3 IDs with the value of 2 and 2 IDs with the value of 3. So `ans[1] = 3`. After step 2, we have 2 IDs with the value of 3. So `ans[2] = 2`. After step 3, we have 2 IDs with the value of 3 and 1 ID with the value of 1. So `ans[3] = 2`. **Example 2:** **Input:** nums = [5,5,3], freq = [2,-2,1] **Output:** [2,0,1] **Explanation:** After step 0, we have 2 IDs with the value of 5. So `ans[0] = 2`. After step 1, there are no IDs. So `ans[1] = 0`. After step 2, we have 1 ID with the value of 3. So `ans[2] = 1`. **Constraints:** `1 <= nums.length == freq.length <= 105` `1 <= nums[i] <= 105` `-105 <= freq[i] <= 105` `freq[i] != 0` The input is generated such that the occurrences of an ID will not be negative in any step.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [2,3,2,1], freq = [3,2,-3,1]",
12
+ "output": "[3,3,2,2] "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [5,5,3], freq = [2,-2,1]",
17
+ "output": "[2,0,1] "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "Addition of IDs: If freq[i] is positive, it means freq[i] IDs with the value nums[i] are added to the collection at step i.",
22
+ "Removal of IDs: If freq[i] is negative, it means -freq[i] IDs with the value nums[i] are removed from the collection at step i.",
23
+ "1 <= nums.length == freq.length <= 105",
24
+ "1 <= nums[i] <= 105",
25
+ "-105 <= freq[i] <= 105",
26
+ "freq[i] != 0",
27
+ "The input is generated such that the occurrences of an ID will not be negative in any step."
28
+ ],
29
+ "python_template": "class Solution(object):\n def mostFrequentIDs(self, nums, freq):\n \"\"\"\n :type nums: List[int]\n :type freq: List[int]\n :rtype: List[int]\n \"\"\"\n ",
30
+ "java_template": "class Solution {\n public long[] mostFrequentIDs(int[] nums, int[] freq) {\n \n }\n}",
31
+ "metadata": {
32
+ "func_name": "mostFrequentIDs"
33
+ }
34
+ }
most-frequent-number-following-key-in-an-array.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2312,
3
+ "name": "most-frequent-number-following-key-in-an-array",
4
+ "difficulty": "Easy",
5
+ "link": "https://leetcode.com/problems/most-frequent-number-following-key-in-an-array/",
6
+ "date": "2022-02-19",
7
+ "task_description": "You are given a **0-indexed** integer array `nums`.** **You are also given an integer `key`, which is present in `nums`. For every unique integer `target` in `nums`, **count** the number of times `target` immediately follows an occurrence of `key` in `nums`. In other words, count the number of indices `i` such that: `0 <= i <= nums.length - 2`, `nums[i] == key` and, `nums[i + 1] == target`. Return _the _`target`_ with the **maximum** count_. The test cases will be generated such that the `target` with maximum count is unique. **Example 1:** ``` **Input:** nums = [1,100,200,1,100], key = 1 **Output:** 100 **Explanation:** For target = 100, there are 2 occurrences at indices 1 and 4 which follow an occurrence of key. No other integers follow an occurrence of key, so we return 100. ``` **Example 2:** ``` **Input:** nums = [2,2,2,2,3], key = 2 **Output:** 2 **Explanation:** For target = 2, there are 3 occurrences at indices 1, 2, and 3 which follow an occurrence of key. For target = 3, there is only one occurrence at index 4 which follows an occurrence of key. target = 2 has the maximum number of occurrences following an occurrence of key, so we return 2. ``` **Constraints:** `2 <= nums.length <= 1000` `1 <= nums[i] <= 1000` The test cases will be generated such that the answer is unique.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [1,100,200,1,100], key = 1",
12
+ "output": "100 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [2,2,2,2,3], key = 2",
17
+ "output": "2 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "0 <= i <= nums.length - 2,",
22
+ "nums[i] == key and,",
23
+ "nums[i + 1] == target.",
24
+ "2 <= nums.length <= 1000",
25
+ "1 <= nums[i] <= 1000",
26
+ "The test cases will be generated such that the answer is unique."
27
+ ],
28
+ "python_template": "class Solution(object):\n def mostFrequent(self, nums, key):\n \"\"\"\n :type nums: List[int]\n :type key: int\n :rtype: int\n \"\"\"\n ",
29
+ "java_template": "class Solution {\n public int mostFrequent(int[] nums, int key) {\n \n }\n}",
30
+ "metadata": {
31
+ "func_name": "mostFrequent"
32
+ }
33
+ }
most-frequent-prime.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3314,
3
+ "name": "most-frequent-prime",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/most-frequent-prime/",
6
+ "date": "2024-02-11",
7
+ "task_description": "You are given a `m x n` **0-indexed **2D** **matrix `mat`. From every cell, you can create numbers in the following way: There could be at most `8` paths from the cells namely: east, south-east, south, south-west, west, north-west, north, and north-east. Select a path from them and append digits in this path to the number being formed by traveling in this direction. Note that numbers are generated at every step, for example, if the digits along the path are `1, 9, 1`, then there will be three numbers generated along the way: `1, 19, 191`. Return _the most frequent prime number **greater** than _`10`_ out of all the numbers created by traversing the matrix or _`-1`_ if no such prime number exists. If there are multiple prime numbers with the highest frequency, then return the largest among them._ **Note:** It is invalid to change the direction during the move. **Example 1:** ** ** ``` ** Input:** mat = [[1,1],[9,9],[1,1]] **Output:** 19 **Explanation:** From cell (0,0) there are 3 possible directions and the numbers greater than 10 which can be created in those directions are: East: [11], South-East: [19], South: [19,191]. Numbers greater than 10 created from the cell (0,1) in all possible directions are: [19,191,19,11]. Numbers greater than 10 created from the cell (1,0) in all possible directions are: [99,91,91,91,91]. Numbers greater than 10 created from the cell (1,1) in all possible directions are: [91,91,99,91,91]. Numbers greater than 10 created from the cell (2,0) in all possible directions are: [11,19,191,19]. Numbers greater than 10 created from the cell (2,1) in all possible directions are: [11,19,19,191]. The most frequent prime number among all the created numbers is 19. ``` **Example 2:** ``` **Input:** mat = [[7]] **Output:** -1 **Explanation:** The only number which can be formed is 7. It is a prime number however it is not greater than 10, so return -1. ``` **Example 3:** ``` **Input:** mat = [[9,7,8],[4,6,5],[2,8,6]] **Output:** 97 **Explanation:** Numbers greater than 10 created from the cell (0,0) in all possible directions are: [97,978,96,966,94,942]. Numbers greater than 10 created from the cell (0,1) in all possible directions are: [78,75,76,768,74,79]. Numbers greater than 10 created from the cell (0,2) in all possible directions are: [85,856,86,862,87,879]. Numbers greater than 10 created from the cell (1,0) in all possible directions are: [46,465,48,42,49,47]. Numbers greater than 10 created from the cell (1,1) in all possible directions are: [65,66,68,62,64,69,67,68]. Numbers greater than 10 created from the cell (1,2) in all possible directions are: [56,58,56,564,57,58]. Numbers greater than 10 created from the cell (2,0) in all possible directions are: [28,286,24,249,26,268]. Numbers greater than 10 created from the cell (2,1) in all possible directions are: [86,82,84,86,867,85]. Numbers greater than 10 created from the cell (2,2) in all possible directions are: [68,682,66,669,65,658]. The most frequent prime number among all the created numbers is 97. ``` **Constraints:** `m == mat.length` `n == mat[i].length` `1 <= m, n <= 6` `1 <= mat[i][j] <= 9`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "mat = [[1,1],[9,9],[1,1]]",
12
+ "output": "19 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "mat = [[7]]",
17
+ "output": "-1 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "mat = [[9,7,8],[4,6,5],[2,8,6]]",
22
+ "output": "97 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "There could be at most 8 paths from the cells namely: east, south-east, south, south-west, west, north-west, north, and north-east.",
27
+ "Select a path from them and append digits in this path to the number being formed by traveling in this direction.",
28
+ "Note that numbers are generated at every step, for example, if the digits along the path are 1, 9, 1, then there will be three numbers generated along the way: 1, 19, 191.",
29
+ "m == mat.length",
30
+ "n == mat[i].length",
31
+ "1 <= m, n <= 6",
32
+ "1 <= mat[i][j] <= 9"
33
+ ],
34
+ "python_template": "class Solution(object):\n def mostFrequentPrime(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"\n ",
35
+ "java_template": "class Solution {\n public int mostFrequentPrime(int[][] mat) {\n \n }\n}",
36
+ "metadata": {
37
+ "func_name": "mostFrequentPrime"
38
+ }
39
+ }
most-popular-video-creator.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2543,
3
+ "name": "most-popular-video-creator",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/most-popular-video-creator/",
6
+ "date": "2022-10-23",
7
+ "task_description": "You are given two string arrays `creators` and `ids`, and an integer array `views`, all of length `n`. The `ith` video on a platform was created by `creators[i]`, has an id of `ids[i]`, and has `views[i]` views. The **popularity** of a creator is the **sum** of the number of views on **all** of the creator's videos. Find the creator with the **highest** popularity and the id of their **most** viewed video. If multiple creators have the highest popularity, find all of them. If multiple videos have the highest view count for a creator, find the lexicographically **smallest** id. Note: It is possible for different videos to have the same `id`, meaning that `id`s do not uniquely identify a video. For example, two videos with the same ID are considered as distinct videos with their own viewcount. Return_ _a **2D array** of **strings** `answer` where `answer[i] = [creatorsi, idi]` means that `creatorsi` has the **highest** popularity and `idi` is the **id** of their most **popular** video. The answer can be returned in any order. **Example 1:** **Input:** creators = [\"alice\",\"bob\",\"alice\",\"chris\"], ids = [\"one\",\"two\",\"three\",\"four\"], views = [5,10,5,4] **Output:** [[\"alice\",\"one\"],[\"bob\",\"two\"]] **Explanation:** The popularity of alice is 5 + 5 = 10. The popularity of bob is 10. The popularity of chris is 4. alice and bob are the most popular creators. For bob, the video with the highest view count is \"two\". For alice, the videos with the highest view count are \"one\" and \"three\". Since \"one\" is lexicographically smaller than \"three\", it is included in the answer. **Example 2:** **Input:** creators = [\"alice\",\"alice\",\"alice\"], ids = [\"a\",\"b\",\"c\"], views = [1,2,2] **Output:** [[\"alice\",\"b\"]] **Explanation:** The videos with id \"b\" and \"c\" have the highest view count. Since \"b\" is lexicographically smaller than \"c\", it is included in the answer. **Constraints:** `n == creators.length == ids.length == views.length` `1 <= n <= 105` `1 <= creators[i].length, ids[i].length <= 5` `creators[i]` and `ids[i]` consist only of lowercase English letters. `0 <= views[i] <= 105`",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "creators = [\"alice\",\"bob\",\"alice\",\"chris\"], ids = [\"one\",\"two\",\"three\",\"four\"], views = [5,10,5,4]",
12
+ "output": "[[\"alice\",\"one\"],[\"bob\",\"two\"]] "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "creators = [\"alice\",\"alice\",\"alice\"], ids = [\"a\",\"b\",\"c\"], views = [1,2,2]",
17
+ "output": "[[\"alice\",\"b\"]] "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "If multiple creators have the highest popularity, find all of them.",
22
+ "If multiple videos have the highest view count for a creator, find the lexicographically smallest id.",
23
+ "n == creators.length == ids.length == views.length",
24
+ "1 <= n <= 105",
25
+ "1 <= creators[i].length, ids[i].length <= 5",
26
+ "creators[i] and ids[i] consist only of lowercase English letters.",
27
+ "0 <= views[i] <= 105"
28
+ ],
29
+ "python_template": "class Solution(object):\n def mostPopularCreator(self, creators, ids, views):\n \"\"\"\n :type creators: List[str]\n :type ids: List[str]\n :type views: List[int]\n :rtype: List[List[str]]\n \"\"\"\n ",
30
+ "java_template": "class Solution {\n public List<List<String>> mostPopularCreator(String[] creators, String[] ids, int[] views) {\n \n }\n}",
31
+ "metadata": {
32
+ "func_name": "mostPopularCreator"
33
+ }
34
+ }
most-profitable-path-in-a-tree.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2564,
3
+ "name": "most-profitable-path-in-a-tree",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/most-profitable-path-in-a-tree/",
6
+ "date": "2022-10-29",
7
+ "task_description": "There is an undirected tree with `n` nodes labeled from `0` to `n - 1`, rooted at node `0`. You are given a 2D integer array `edges` of length `n - 1` where `edges[i] = [ai, bi]` indicates that there is an edge between nodes `ai` and `bi` in the tree. At every node `i`, there is a gate. You are also given an array of even integers `amount`, where `amount[i]` represents: the price needed to open the gate at node `i`, if `amount[i]` is negative, or, the cash reward obtained on opening the gate at node `i`, otherwise. The game goes on as follows: Initially, Alice is at node `0` and Bob is at node `bob`. At every second, Alice and Bob each move to an adjacent node. Alice moves towards some **leaf node**, while Bob moves towards node `0`. For **every** node along their path, Alice and Bob either spend money to open the gate at that node, or accept the reward. Note that: If the gate is **already open**, no price will be required, nor will there be any cash reward. If Alice and Bob reach the node **simultaneously**, they share the price/reward for opening the gate there. In other words, if the price to open the gate is `c`, then both Alice and Bob pay `c / 2` each. Similarly, if the reward at the gate is `c`, both of them receive `c / 2` each. If Alice reaches a leaf node, she stops moving. Similarly, if Bob reaches node `0`, he stops moving. Note that these events are **independent** of each other. Return_ the **maximum** net income Alice can have if she travels towards the optimal leaf node._ **Example 1:** ``` **Input:** edges = [[0,1],[1,2],[1,3],[3,4]], bob = 3, amount = [-2,4,2,-4,6] **Output:** 6 **Explanation:** The above diagram represents the given tree. The game goes as follows: - Alice is initially on node 0, Bob on node 3. They open the gates of their respective nodes. Alice's net income is now -2. - Both Alice and Bob move to node 1. Since they reach here simultaneously, they open the gate together and share the reward. Alice's net income becomes -2 + (4 / 2) = 0. - Alice moves on to node 3. Since Bob already opened its gate, Alice's income remains unchanged. Bob moves on to node 0, and stops moving. - Alice moves on to node 4 and opens the gate there. Her net income becomes 0 + 6 = 6. Now, neither Alice nor Bob can make any further moves, and the game ends. It is not possible for Alice to get a higher net income. ``` **Example 2:** ``` **Input:** edges = [[0,1]], bob = 1, amount = [-7280,2350] **Output:** -7280 **Explanation:** Alice follows the path 0->1 whereas Bob follows the path 1->0. Thus, Alice opens the gate at node 0 only. Hence, her net income is -7280. ``` **Constraints:** `2 <= n <= 105` `edges.length == n - 1` `edges[i].length == 2` `0 <= ai, bi < n` `ai != bi` `edges` represents a valid tree. `1 <= bob < n` `amount.length == n` `amount[i]` is an **even** integer in the range `[-104, 104]`.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "edges = [[0,1],[1,2],[1,3],[3,4]], bob = 3, amount = [-2,4,2,-4,6]",
12
+ "output": "6 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "edges = [[0,1]], bob = 1, amount = [-7280,2350]",
17
+ "output": "-7280 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "the price needed to open the gate at node i, if amount[i] is negative, or,",
22
+ "the cash reward obtained on opening the gate at node i, otherwise.",
23
+ "Initially, Alice is at node 0 and Bob is at node bob.",
24
+ "At every second, Alice and Bob each move to an adjacent node. Alice moves towards some leaf node, while Bob moves towards node 0.",
25
+ "For every node along their path, Alice and Bob either spend money to open the gate at that node, or accept the reward. Note that:\n\t\nIf the gate is already open, no price will be required, nor will there be any cash reward.\nIf Alice and Bob reach the node simultaneously, they share the price/reward for opening the gate there. In other words, if the price to open the gate is c, then both Alice and Bob pay c / 2 each. Similarly, if the reward at the gate is c, both of them receive c / 2 each.",
26
+ "If the gate is already open, no price will be required, nor will there be any cash reward.",
27
+ "If Alice and Bob reach the node simultaneously, they share the price/reward for opening the gate there. In other words, if the price to open the gate is c, then both Alice and Bob pay c / 2 each. Similarly, if the reward at the gate is c, both of them receive c / 2 each.",
28
+ "If Alice reaches a leaf node, she stops moving. Similarly, if Bob reaches node 0, he stops moving. Note that these events are independent of each other.",
29
+ "If the gate is already open, no price will be required, nor will there be any cash reward.",
30
+ "If Alice and Bob reach the node simultaneously, they share the price/reward for opening the gate there. In other words, if the price to open the gate is c, then both Alice and Bob pay c / 2 each. Similarly, if the reward at the gate is c, both of them receive c / 2 each.",
31
+ "2 <= n <= 105",
32
+ "edges.length == n - 1",
33
+ "edges[i].length == 2",
34
+ "0 <= ai, bi < n",
35
+ "ai != bi",
36
+ "edges represents a valid tree.",
37
+ "1 <= bob < n",
38
+ "amount.length == n",
39
+ "amount[i] is an even integer in the range [-104, 104]."
40
+ ],
41
+ "python_template": "class Solution(object):\n def mostProfitablePath(self, edges, bob, amount):\n \"\"\"\n :type edges: List[List[int]]\n :type bob: int\n :type amount: List[int]\n :rtype: int\n \"\"\"\n ",
42
+ "java_template": "class Solution {\n public int mostProfitablePath(int[][] edges, int bob, int[] amount) {\n \n }\n}",
43
+ "metadata": {
44
+ "func_name": "mostProfitablePath"
45
+ }
46
+ }
move-pieces-to-obtain-a-string.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2414,
3
+ "name": "move-pieces-to-obtain-a-string",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/move-pieces-to-obtain-a-string/",
6
+ "date": "2022-07-03",
7
+ "task_description": "You are given two strings `start` and `target`, both of length `n`. Each string consists **only** of the characters `'L'`, `'R'`, and `'_'` where: The characters `'L'` and `'R'` represent pieces, where a piece `'L'` can move to the **left** only if there is a **blank** space directly to its left, and a piece `'R'` can move to the **right** only if there is a **blank** space directly to its right. The character `'_'` represents a blank space that can be occupied by **any** of the `'L'` or `'R'` pieces. Return `true` _if it is possible to obtain the string_ `target`_ by moving the pieces of the string _`start`_ **any** number of times_. Otherwise, return `false`. **Example 1:** ``` **Input:** start = \"_L__R__R_\", target = \"L______RR\" **Output:** true **Explanation:** We can obtain the string target from start by doing the following moves: - Move the first piece one step to the left, start becomes equal to \"**L**___R__R_\". - Move the last piece one step to the right, start becomes equal to \"L___R___**R**\". - Move the second piece three steps to the right, start becomes equal to \"L______**R**R\". Since it is possible to get the string target from start, we return true. ``` **Example 2:** ``` **Input:** start = \"R_L_\", target = \"__LR\" **Output:** false **Explanation:** The 'R' piece in the string start can move one step to the right to obtain \"_**R**L_\". After that, no pieces can move anymore, so it is impossible to obtain the string target from start. ``` **Example 3:** ``` **Input:** start = \"_R\", target = \"R_\" **Output:** false **Explanation:** The piece in the string start can move only to the right, so it is impossible to obtain the string target from start. ``` **Constraints:** `n == start.length == target.length` `1 <= n <= 105` `start` and `target` consist of the characters `'L'`, `'R'`, and `'_'`.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "start = \"_L__R__R_\", target = \"L______RR\"",
12
+ "output": "true "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "start = \"R_L_\", target = \"__LR\"",
17
+ "output": "false "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "start = \"_R\", target = \"R_\"",
22
+ "output": "false "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "The characters 'L' and 'R' represent pieces, where a piece 'L' can move to the left only if there is a blank space directly to its left, and a piece 'R' can move to the right only if there is a blank space directly to its right.",
27
+ "The character '_' represents a blank space that can be occupied by any of the 'L' or 'R' pieces.",
28
+ "n == start.length == target.length",
29
+ "1 <= n <= 105",
30
+ "start and target consist of the characters 'L', 'R', and '_'."
31
+ ],
32
+ "python_template": "class Solution(object):\n def canChange(self, start, target):\n \"\"\"\n :type start: str\n :type target: str\n :rtype: bool\n \"\"\"\n ",
33
+ "java_template": "class Solution {\n public boolean canChange(String start, String target) {\n \n }\n}",
34
+ "metadata": {
35
+ "func_name": "canChange"
36
+ }
37
+ }
movement-of-robots.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2787,
3
+ "name": "movement-of-robots",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/movement-of-robots/",
6
+ "date": "2023-05-27",
7
+ "task_description": "Some robots are standing on an infinite number line with their initial coordinates given by a **0-indexed** integer array `nums` and will start moving once given the command to move. The robots will move a unit distance each second. You are given a string `s` denoting the direction in which robots will move on command. `'L'` means the robot will move towards the left side or negative side of the number line, whereas `'R'` means the robot will move towards the right side or positive side of the number line. If two robots collide, they will start moving in opposite directions. Return _the sum of distances between all the pairs of robots _`d` _seconds after the command. _Since the sum can be very large, return it modulo `109 + 7`. Note: For two robots at the index `i` and `j`, pair `(i,j)` and pair `(j,i)` are considered the same pair. When robots collide, they **instantly change** their directions without wasting any time. Collision happens when two robots share the same place in a moment. For example, if a robot is positioned in 0 going to the right and another is positioned in 2 going to the left, the next second they'll be both in 1 and they will change direction and the next second the first one will be in 0, heading left, and another will be in 2, heading right. For example, if a robot is positioned in 0 going to the right and another is positioned in 1 going to the left, the next second the first one will be in 0, heading left, and another will be in 1, heading right. **Example 1:** ``` **Input:** nums = [-2,0,2], s = \"RLL\", d = 3 **Output:** 8 **Explanation:** After 1 second, the positions are [-1,-1,1]. Now, the robot at index 0 will move left, and the robot at index 1 will move right. After 2 seconds, the positions are [-2,0,0]. Now, the robot at index 1 will move left, and the robot at index 2 will move right. After 3 seconds, the positions are [-3,-1,1]. The distance between the robot at index 0 and 1 is abs(-3 - (-1)) = 2. The distance between the robot at index 0 and 2 is abs(-3 - 1) = 4. The distance between the robot at index 1 and 2 is abs(-1 - 1) = 2. The sum of the pairs of all distances = 2 + 4 + 2 = 8. ``` **Example 2:** ``` **Input:** nums = [1,0], s = \"RL\", d = 2 **Output:** 5 **Explanation:** After 1 second, the positions are [2,-1]. After 2 seconds, the positions are [3,-2]. The distance between the two robots is abs(-2 - 3) = 5. ``` **Constraints:** `2 <= nums.length <= 105` `-2 * 109 <= nums[i] <= 2 * 109` `0 <= d <= 109` `nums.length == s.length ` `s` consists of 'L' and 'R' only `nums[i]` will be unique.",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [-2,0,2], s = \"RLL\", d = 3",
12
+ "output": "8 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [1,0], s = \"RL\", d = 2",
17
+ "output": "5 "
18
+ }
19
+ ],
20
+ "constraints": [
21
+ "For two robots at the index i and j, pair (i,j) and pair (j,i) are considered the same pair.",
22
+ "When robots collide, they instantly change their directions without wasting any time.",
23
+ "Collision happens when two robots share the same place in a moment.\n\t\nFor example, if a robot is positioned in 0 going to the right and another is positioned in 2 going to the left, the next second they'll be both in 1 and they will change direction and the next second the first one will be in 0, heading left, and another will be in 2, heading right.\nFor example, if a robot is positioned in 0 going to the right and another is positioned in 1 going to the left, the next second the first one will be in 0, heading left, and another will be in 1, heading right.",
24
+ "For example, if a robot is positioned in 0 going to the right and another is positioned in 2 going to the left, the next second they'll be both in 1 and they will change direction and the next second the first one will be in 0, heading left, and another will be in 2, heading right.",
25
+ "For example, if a robot is positioned in 0 going to the right and another is positioned in 1 going to the left, the next second the first one will be in 0, heading left, and another will be in 1, heading right.",
26
+ "For example, if a robot is positioned in 0 going to the right and another is positioned in 2 going to the left, the next second they'll be both in 1 and they will change direction and the next second the first one will be in 0, heading left, and another will be in 2, heading right.",
27
+ "For example, if a robot is positioned in 0 going to the right and another is positioned in 1 going to the left, the next second the first one will be in 0, heading left, and another will be in 1, heading right.",
28
+ "2 <= nums.length <= 105",
29
+ "-2 * 109 <= nums[i] <= 2 * 109",
30
+ "0 <= d <= 109",
31
+ "nums.length == s.length",
32
+ "s consists of 'L' and 'R' only",
33
+ "nums[i] will be unique."
34
+ ],
35
+ "python_template": "class Solution(object):\n def sumDistance(self, nums, s, d):\n \"\"\"\n :type nums: List[int]\n :type s: str\n :type d: int\n :rtype: int\n \"\"\"\n ",
36
+ "java_template": "class Solution {\n public int sumDistance(int[] nums, String s, int d) {\n \n }\n}",
37
+ "metadata": {
38
+ "func_name": "sumDistance"
39
+ }
40
+ }
neighboring-bitwise-xor.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2792,
3
+ "name": "neighboring-bitwise-xor",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/neighboring-bitwise-xor/",
6
+ "date": "2023-05-07",
7
+ "task_description": "A **0-indexed** array `derived` with length `n` is derived by computing the **bitwise XOR** (⊕) of adjacent values in a **binary array** `original` of length `n`. Specifically, for each index `i` in the range `[0, n - 1]`: If `i = n - 1`, then `derived[i] = original[i] ⊕ original[0]`. Otherwise, `derived[i] = original[i] ⊕ original[i + 1]`. Given an array `derived`, your task is to determine whether there exists a **valid binary array** `original` that could have formed `derived`. Return _**true** if such an array exists or **false** otherwise._ A binary array is an array containing only **0's** and **1's** **Example 1:** ``` **Input:** derived = [1,1,0] **Output:** true **Explanation:** A valid original array that gives derived is [0,1,0]. derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1 derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1 derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0 ``` **Example 2:** ``` **Input:** derived = [1,1] **Output:** true **Explanation:** A valid original array that gives derived is [0,1]. derived[0] = original[0] ⊕ original[1] = 1 derived[1] = original[1] ⊕ original[0] = 1 ``` **Example 3:** ``` **Input:** derived = [1,0] **Output:** false **Explanation:** There is no valid original array that gives derived. ``` **Constraints:** `n == derived.length` `1 <= n <= 105` The values in `derived` are either **0's** or **1's**",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "derived = [1,1,0]",
12
+ "output": "true "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "derived = [1,1]",
17
+ "output": "true "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "derived = [1,0]",
22
+ "output": "false "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "If i = n - 1, then derived[i] = original[i] ⊕ original[0].",
27
+ "Otherwise, derived[i] = original[i] ⊕ original[i + 1].",
28
+ "A binary array is an array containing only 0's and 1's",
29
+ "n == derived.length",
30
+ "1 <= n <= 105",
31
+ "The values in derived are either 0's or 1's"
32
+ ],
33
+ "python_template": "class Solution(object):\n def doesValidArrayExist(self, derived):\n \"\"\"\n :type derived: List[int]\n :rtype: bool\n \"\"\"\n ",
34
+ "java_template": "class Solution {\n public boolean doesValidArrayExist(int[] derived) {\n \n }\n}",
35
+ "metadata": {
36
+ "func_name": "doesValidArrayExist"
37
+ }
38
+ }
neither-minimum-nor-maximum.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2836,
3
+ "name": "neither-minimum-nor-maximum",
4
+ "difficulty": "Easy",
5
+ "link": "https://leetcode.com/problems/neither-minimum-nor-maximum/",
6
+ "date": "2023-06-04",
7
+ "task_description": "Given an integer array `nums` containing **distinct** **positive** integers, find and return **any** number from the array that is neither the **minimum** nor the **maximum** value in the array, or **`-1`** if there is no such number. Return _the selected integer._ **Example 1:** ``` **Input:** nums = [3,2,1,4] **Output:** 2 **Explanation:** In this example, the minimum value is 1 and the maximum value is 4. Therefore, either 2 or 3 can be valid answers. ``` **Example 2:** ``` **Input:** nums = [1,2] **Output:** -1 **Explanation:** Since there is no number in nums that is neither the maximum nor the minimum, we cannot select a number that satisfies the given condition. Therefore, there is no answer. ``` **Example 3:** ``` **Input:** nums = [2,1,3] **Output:** 2 **Explanation:** Since 2 is neither the maximum nor the minimum value in nums, it is the only valid answer. ``` **Constraints:** `1 <= nums.length <= 100` `1 <= nums[i] <= 100` All values in `nums` are distinct",
8
+ "test_case": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [3,2,1,4]",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [1,2]",
17
+ "output": "-1 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums = [2,1,3]",
22
+ "output": "2 "
23
+ }
24
+ ],
25
+ "constraints": [
26
+ "1 <= nums.length <= 100",
27
+ "1 <= nums[i] <= 100",
28
+ "All values in nums are distinct"
29
+ ],
30
+ "python_template": "class Solution(object):\n def findNonMinOrMax(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ",
31
+ "java_template": "class Solution {\n public int findNonMinOrMax(int[] nums) {\n \n }\n}",
32
+ "metadata": {
33
+ "func_name": "findNonMinOrMax"
34
+ }
35
+ }