int main() {
int t;
cin>>t;
while(t–)
{
string s;
cin>>s;
map<string,int>freq;
map<string,int>::iterator it;
for(int i=0;i<s.size();i++)
{
string p="\0";
p=p+s[i];
if(freq.find§==freq.end())
freq[p]=1;
for(it=freq.begin();it!=freq.end();it++)
{
string b=(it->first)+p;
if(freq.find(b)==freq.end())
freq[b]=1;
}
}
cout<<freq.size()<<endl;
}
}
Why am i getting an infinite loop in this approach
While iterating the map, you are also inserting values in the map, which results in an infinte loop.
how can i correct this?
@neha_153 This approach won’t work because the no of subsequence are so large that you cannot generate all the subsequences.
Here have a look at my code. You have to calculate all the distinct subsequences without generating them.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.