We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 95a781c commit 0320536Copy full SHA for 0320536
longest-repeating-character-replacement/samthekorean.py
@@ -0,0 +1,20 @@
1
+# TC : O(n)
2
+# SC : O(1)
3
+class Solution:
4
+ def characterReplacement(self, s: str, k: int) -> int:
5
+ count = {}
6
+ result = 0
7
+
8
+ left = 0
9
+ maxFrequency = 0
10
+ for right in range(len(s)):
11
+ count[s[right]] = 1 + count.get(s[right], 0)
12
+ maxFrequency = max(maxFrequency, count[s[right]])
13
14
+ while (right - left + 1) - maxFrequency > k:
15
+ count[s[left]] -= 1
16
+ left += 1
17
18
+ result = max(result, right - left + 1)
19
20
+ return result
0 commit comments