create a multi set. check everytime a char is entered if its count is less than x increase counter else do k-- as long as k isn’t -1 else break . unable to see why I’m getting wa
using namespace std;
long long counter=0;
multiset <string> stringSet;
unordered_map <string,int> um1;
if(stringSet.find(string(1,s[i])) == stringSet.end() && stringSet.count(string(1,s[i]))<=x)
Doesnt your code always print N? You seem to be entering and checking frequency of prefix rather than characters.
sample test cases passed so its definitely not always n.the for loop runs till the length of string
so before i insert a char i see if it exists and if it does is its count less than x and add counter. if not i subtract k.
if i have no k to subtract i break the program ending the for loop
my string(1,s[i]) is just to make it compatible so that char and str dont mismatch
I noticed your condition to increment answer is-
- Searching for that char should yield end of container. Meaning the char should have frequency 0.
- The freq should be <=x
Your first condition is wrong. Please see if it helps
that was the problem. thank you very much