leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 222dc17f88ba6672609f9ea009d251eb681468bd |
parent | b6ac96e045f08c6ef289426cee2f6139d63d9e5b |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Sat, 4 Mar 2023 12:59:02 +0100 |
Daily Problem
Diffstat:A | Problems/2444.cpp | | | +++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/Problems/2444.cpp b/Problems/2444.cpp
@@ -0,0 +1,19 @@
class Solution {
public:
long long countSubarrays(vector<int> &nums, int minK, int maxK) {
int n = nums.size(), leftBound = -1, lastMin = -1, lastMax = -1;
long long count = 0;
for (int i = 0; i < n; i++) {
if (nums[i] < minK || nums[i] > maxK) {
leftBound = i, lastMin = -1, lastMax = -1;
continue;
}
if (nums[i] == minK) lastMin = i;
if (nums[i] == maxK) lastMax = i;
count += max(0, min(lastMin, lastMax) - leftBound);
}
return count;
}
};
diff --git a/README.md b/README.md
@@ -462,6 +462,7 @@ for solving problems.
| 2374 | Medium | [Node With Highest Edge Score](Problems/2374.cpp) |
| 2390 | Medium | [Removing Stars From a String](Problems/2390.cpp) |
| 2421 | Medium | [Number of Good Paths](Problems/2421.cpp) |
| 2444 | Hard | [Count Subarrays With Fixed Bounds](Problems/2444.cpp) |
| 2461 | Medium | [Maximum Sum of Distinct Subarrays With Length K](Problems/2461.cpp) |
| 2465 | Easy | [Number of Distinct Averages](Problems/2465.cpp) |
| 2466 | Medium | [Count Ways To Build Good Strings](Problems/2466.cpp) |