commit 12d3b277506d3df88ee0bf42d4d25383406280b5
parent eebb47978e7c8ceed09a4d76572a7608b287066e
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Wed, 24 Apr 2024 15:12:12 +0200
1 Random Problem
Diffstat:
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/Problems/1297.cpp b/Problems/1297.cpp
@@ -0,0 +1,22 @@
+class Solution {
+ public:
+ int maxFreq(const string &s, int maxLetters, int sz, int _) const {
+ unordered_map<string, int> um;
+ static int count[26];
+ int res = 0, uniq = 0;
+
+ memset(count, 0x00, sizeof(count));
+ for (int i = 0; i < sz; i++)
+ if (!count[s[i] - 'a']++) uniq++;
+ for (int i = sz; i < size(s); i++) {
+ if (uniq <= maxLetters) um[s.substr(i - sz, sz)]++;
+ if (!--count[s[i - sz] - 'a']) uniq--;
+ if (!count[s[i] - 'a']++) uniq++;
+ }
+
+ if (uniq <= maxLetters) um[s.substr(size(s) - sz, sz)]++;
+ for (const auto [_, c] : um)
+ res = max(res, c);
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -713,6 +713,7 @@ for solving problems.
| 1291 | Medium | [Sequential Digits](Problems/1291.cpp) |
| 1292 | Medium | [Maximum Side Length of a Square with Sum Less than or Equal to Threshold](Problems/1292.cpp) |
| 1296 | Medium | [Divide Array in Sets of K Consecutive Numbers](Problems/1296.cpp) |
+| 1297 | Medium | [Maximum Number of Occurrences of a Substring](Problems/1297.cpp) |
| 1302 | Medium | [Deepest Leaves Sum](Problems/1302.cpp) |
| 1305 | Medium | [All Elements in Two Binary Search Trees](Problems/1305.cpp) |
| 1306 | Medium | [Jump Game III](Problems/1306.cpp) |