commit 6f19a39f522baa6e0f87c269ef9175a626bbffd3
parent 2e2afaeb9584c00ccc92390e8efaa7b56efb5ccb
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Tue, 28 May 2024 17:44:14 +0200
Daily Problem
Diffstat:
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/Problems/1208.cpp b/Problems/1208.cpp
@@ -0,0 +1,18 @@
+class Solution {
+ public:
+ int equalSubstring(const string &s, const string &t, const int maxCost) const {
+ const int n = size(s);
+ int res = 0, total = 0;
+
+ for (int i = 0, j = 0; i < n; i++) {
+ total += abs(s[i] - t[i]);
+ while (maxCost < total) {
+ total -= abs(s[j] - t[j]);
+ j++;
+ }
+ res = max(res, i - j + 1);
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -689,6 +689,7 @@ for solving problems.
| 1203 | Hard | [Sort Items by Groups Respecting Dependencies](Problems/1203.cpp) |
| 1204 | Medium | [Last Person to Fit in the Bus](Problems/1204.cpp) |
| 1207 | Easy | [Unique Number of Occurrences](Problems/1207.cpp) |
+| 1208 | Medium | [Get Equal Substrings Within Budget](Problems/1208.cpp) |
| 1209 | Medium | [Remove All Adjacent Duplicates in String II](Problems/1209.cpp) |
| 1211 | Easy | [Queries Quality and Percentage](Problems/1211.cpp) |
| 1218 | Medium | [Longest Arithmetic Subsequence of Given Difference](Problems/1218.cpp) |