Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.
#include<cstdio>
bool pd[26];
char s[1000007];
int n,k,size,last[26];
int main(){
scanf(“%d%d%s”,&n,&k,&s);
for (int i=0;i<n;++i) last[s[i]-‘A’]=i;
for (int i=0;i<n;++i){
if (!pd[s[i]-‘A’]) pd[s[i]-‘A’]=true,++size;
if (size>k){
printf(“YES”);
return 0;
}
if (i==last[s[i]-‘A’]) –size;
}
printf(“NO”);
}
📦 Looking for Codeforces Round 426 Div Problem Festive? Check the best deals on Amazon.
🛒 Shop Codeforces Round 426 Div Problem Festive on Amazon
As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.
Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.
#include<cstdio>
bool pd[26];
char s[1000007];
int n,k,size,last[26];
int main(){
scanf(“%d%d%s”,&n,&k,&s);
for (int i=0;i<n;++i) last[s[i]-‘A’]=i;
for (int i=0;i<n;++i){
if (!pd[s[i]-‘A’]) pd[s[i]-‘A’]=true,++size;
if (size>k){
printf(“YES”);
return 0;
}
if (i==last[s[i]-‘A’]) –size;
}
printf(“NO”);
}
📦 Looking for Codeforces Round 426 Div Problem Festive? Check the best deals on Amazon.
🛒 Shop Codeforces Round 426 Div Problem Festive on Amazon
As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.