209.minimum-size-subarray-sum
🟡 2023-07-06
#array #binary_search #sliding_window #prefix_sum
Given an array of positive integers
Example 1:
Example 2:
Example 3:
Constraints:
●
●
●
Follow up: If you have figured out the
via LeetCode Daily Question
🟡 2023-07-06
#array #binary_search #sliding_window #prefix_sum
Given an array of positive integers
nums
and a positive integer target
, return the minimal length of a subarray whose sum is greater than or equal to target
. If there is no such subarray, return 0
instead.Example 1:
Input: target = 7, nums = [2,3,1,2,4,3]
Output: 2
Explanation: The subarray [4,3] has the minimal length under the problem constraint.
Example 2:
Input: target = 4, nums = [1,4,4]
Output: 1
Example 3:
Input: target = 11, nums = [1,1,1,1,1,1,1,1]
Output: 0
Constraints:
●
1 <= target <= 109
●
1 <= nums.length <= 105
●
1 <= nums[i] <= 104
Follow up: If you have figured out the
O(n)
solution, try coding another solution of which the time complexity is O(n log(n))
.via LeetCode Daily Question
2410.maximum-matching-of-players-with-trainers
🟡 2025-07-13
#array #two_pointers #greedy #sorting
You are given a 0-indexed integer array
The
Return the maximum number of matchings between
Example 1:
Example 2:
Constraints:
●
●
Note: This question is the same as 445: Assign Cookies.
🟡 2025-07-13
#array #two_pointers #greedy #sorting
You are given a 0-indexed integer array
players
, where players[i]
represents the ability of the ith
player. You are also given a 0-indexed integer array trainers
, where trainers[j]
represents the training capacity of the jth
trainer.The
ith
player can match with the jth
trainer if the player's ability is less than or equal to the trainer's training capacity. Additionally, the ith
player can be matched with at most one trainer, and the jth
trainer can be matched with at most one player.Return the maximum number of matchings between
players
and trainers
that satisfy these conditions.Example 1:
Input: players = [4,7,9], trainers = [8,2,5,8]
Output: 2
Explanation:
One of the ways we can form two matchings is as follows:
- players[0] can be matched with trainers[0] since 4 <= 8.
- players[1] can be matched with trainers[3] since 7 <= 8.
It can be proven that 2 is the maximum number of matchings that can be formed.
Example 2:
Input: players = [1,1,1], trainers = [10]
Output: 1
Explanation:
The trainer can be matched with any of the 3 players.
Each player can only be matched with one trainer, so the maximum answer is 1.
Constraints:
●
1 <= players.length, trainers.length <= 105
●
1 <= players[i], trainers[j] <= 109
Note: This question is the same as 445: Assign Cookies.
2163.minimum-difference-in-sums-after-removal-of-elements
🔴 2025-07-18
#array #dynamic_programming #heap_priority_queue
You are given a 0-indexed integer array
You are allowed to remove any subsequence of elements of size exactly
● The first
● The next
The difference in sums of the two parts is denoted as
● For example, if
● Similarly, if
Return the minimum difference possible between the sums of the two parts after the removal of
Example 1:
Example 2:
Constraints:
●
●
●
🔴 2025-07-18
#array #dynamic_programming #heap_priority_queue
You are given a 0-indexed integer array
nums
consisting of 3 * n
elements.You are allowed to remove any subsequence of elements of size exactly
n
from nums
. The remaining 2 * n
elements will be divided into two equal parts:● The first
n
elements belonging to the first part and their sum is sumfirst
.● The next
n
elements belonging to the second part and their sum is sumsecond
.The difference in sums of the two parts is denoted as
sumfirst - sumsecond
.● For example, if
sumfirst = 3
and sumsecond = 2
, their difference is 1
.● Similarly, if
sumfirst = 2
and sumsecond = 3
, their difference is -1
.Return the minimum difference possible between the sums of the two parts after the removal of
n
elements.Example 1:
Input: nums = [3,1,2]
Output: -1
Explanation: Here, nums has 3 elements, so n = 1.
Thus we have to remove 1 element from nums and divide the array into two equal parts.
- If we remove nums[0] = 3, the array will be [1,2]. The difference in sums of the two parts will be 1 - 2 = -1.
- If we remove nums[1] = 1, the array will be [3,2]. The difference in sums of the two parts will be 3 - 2 = 1.
- If we remove nums[2] = 2, the array will be [3,1]. The difference in sums of the two parts will be 3 - 1 = 2.
The minimum difference between sums of the two parts is min(-1,1,2) = -1.
Example 2:
Input: nums = [7,9,5,8,1,3]
Output: 1
Explanation: Here n = 2. So we must remove 2 elements and divide the remaining array into two parts containing two elements each.
If we remove nums[2] = 5 and nums[3] = 8, the resultant array will be [7,9,1,3]. The difference in sums will be (7+9) - (1+3) = 12.
To obtain the minimum difference, we should remove nums[1] = 9 and nums[4] = 1. The resultant array becomes [7,5,8,3]. The difference in sums of the two parts is (7+5) - (8+3) = 1.
It can be shown that it is not possible to obtain a difference smaller than 1.
Constraints:
●
nums.length == 3 * n
●
1 <= n <= 105
●
1 <= nums[i] <= 105
1233.remove-sub-folders-from-the-filesystem
🟡 2025-07-19
#array #string #depth_first_search #trie
Given a list of folders
If a
The format of a path is one or more concatenated strings of the form:
● For example,
Example 1:
Example 2:
Example 3:
Constraints:
●
●
●
●
● Each folder name is unique.
🟡 2025-07-19
#array #string #depth_first_search #trie
Given a list of folders
folder
, return the folders after removing all sub-folders in those folders. You may return the answer in any order.If a
folder[i]
is located within another folder[j]
, it is called a sub-folder of it. A sub-folder of folder[j]
must start with folder[j]
, followed by a "/"
. For example, "/a/b"
is a sub-folder of "/a"
, but "/b"
is not a sub-folder of "/a/b/c"
.The format of a path is one or more concatenated strings of the form:
'/'
followed by one or more lowercase English letters.● For example,
"/leetcode"
and "/leetcode/problems"
are valid paths while an empty string and "/"
are not.Example 1:
Input: folder = ["/a","/a/b","/c/d","/c/d/e","/c/f"]
Output: ["/a","/c/d","/c/f"]
Explanation: Folders "/a/b" is a subfolder of "/a" and "/c/d/e" is inside of folder "/c/d" in our filesystem.
Example 2:
Input: folder = ["/a","/a/b/c","/a/b/d"]
Output: ["/a"]
Explanation: Folders "/a/b/c" and "/a/b/d" will be removed because they are subfolders of "/a".
Example 3:
Input: folder = ["/a/b/c","/a/b/ca","/a/b/d"]
Output: ["/a/b/c","/a/b/ca","/a/b/d"]
Constraints:
●
1 <= folder.length <= 4 * 104
●
2 <= folder[i].length <= 100
●
folder[i]
contains only lowercase letters and '/'
.●
folder[i]
always starts with the character '/'
.● Each folder name is unique.