We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b45d6d4 commit e2b99e0Copy full SHA for e2b99e0
Maximum Sub-String after at most K changes
@@ -0,0 +1,40 @@
1
+class Solution {
2
+ public:
3
+ int characterReplacement(string s, int k) {
4
+ int maxLen = 0;
5
+ int cnt = 0;
6
+ int i = 0;
7
+ int j = 0;
8
+ unordered_set<char> st;
9
+ for(auto &e: s){
10
+ st.insert(e);
11
+ }
12
+ for(auto &e : st){
13
+ int currLen = 0;
14
15
16
17
+ while(j < s.size()){
18
+ if(s[j] == e){
19
+ currLen++;
20
+ maxLen = std::max(currLen, maxLen);
21
+ j++;
22
23
+ else{
24
+ cnt++;
25
26
+ while(cnt > k && i <= j){
27
+ if(e != s[i])
28
+ cnt--;
29
+ i++;
30
+ currLen--;
31
32
33
34
35
36
37
+ return maxLen;
38
39
+
40
+};
0 commit comments