commit 24989a7783f4dbb66291d0cd0326a971eb989e16
parent d48b92e41033d5976a9796f48c6fad6292409336
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Thu, 4 Jul 2024 12:53:55 +0200
1 Random Problem
Diffstat:
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/Problems/2537.cpp b/Problems/2537.cpp
@@ -0,0 +1,17 @@
+class Solution {
+ public:
+ long long countGood(const vector<int> &nums, int k) const {
+ unordered_map<int, int> count;
+ const int n = size(nums);
+ long long res = 0;
+
+ for (int i = 0, j = 0; j < n; j++) {
+ k -= count[nums[j]]++;
+ while (k <= 0)
+ k += --count[nums[i++]];
+ res += i;
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -1181,6 +1181,7 @@ for solving problems.
| 2498 | Medium | [Frog Jump II](Problems/2498.cpp) |
| 2517 | Medium | [Maximum Tastiness of Candy Basket](Problems/2517.cpp) |
| 2527 | Medium | [Find Xor-Beauty of Array](Problems/2527.cpp) |
+| 2537 | Medium | [Count the Number of Good Subarrays](Problems/2537.cpp) |
| 2540 | Easy | [Minimum Common Value](Problems/2540.cpp) |
| 2542 | Medium | [Maximum Subsequence Score](Problems/2542.cpp) |
| 2545 | Medium | [Sort the Students by Their Kth Score](Problems/2545.cpp) |