Codeforces Round #797 (Div. 3) 1690D - Black and White Stripe Solution
Problem Link: https://codeforces.com/contest/1690/problem/D
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,x,t,r,k,i,mn;
cin>>t;
while(t--)
{
cin>>n>>k;
x=0;
string s;
cin>>s;
for(i=0; i<k; i++)
{
if(s[i]=='W')
x++;
}
mn=x;
for(i=k;i<n; i++)
{
if(s[i-k]=='W')
x--;
if(s[i]=='W')
x++;
mn=min(x,mn);
}
cout<<mn<<endl;
}
return 0;
}
No comments