Skip to content

Commit cfc6b64

Browse files
Create Sanket and Strings.cpp
1 parent 0600dbf commit cfc6b64

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Coding Blocks/Sanket and Strings.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
#include<cstring>
3+
using namespace std;
4+
int main() {
5+
string s;
6+
long long i,j,k,ans=0,value;
7+
cin>>k;
8+
cin>>s;
9+
long long n=s.length();
10+
for(i=0;i<n;i++)
11+
{
12+
char ch=s[i];
13+
int j=i+1;
14+
int count[]={0,0};
15+
count[ch - 'a']++;
16+
while(j<n)
17+
{
18+
19+
20+
if(min(count[0],count[1])<=k)
21+
{count[s[j] - 'a']++;
22+
j++;
23+
}
24+
else
25+
{
26+
value=j-i;
27+
break;
28+
}
29+
30+
}
31+
if(j!=n)
32+
value=j-i-1;
33+
else
34+
value = j-i;
35+
ans=max(ans,value);
36+
}
37+
cout<<ans;
38+
return 0;
39+
}

0 commit comments

Comments
 (0)