String window error

#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,t;
getline(cin,s);
getline(cin,t);
map<char,int> freq_t,freq_s;
int n=s.size(),m=t.size();

int resl=-1,resr=1e9;
for(auto x:t)
    freq_t[x]++;

int l=0,r=0;
for(r=0;r<n;r++)
{
    
    freq_s[s[r]]++;
    bool good=true;

    for(auto x:freq_t)
    {   
        if(freq_s.count(x.first)==0||(freq_s[x.first]<x.second))// count function tells us that if the key is present in the map it gives 1 if present else 0;
            {
                good=false;
                break;
            }
    }

    if(!good) 
        continue;

    // if good 
    while(l<n && l<=r &&(freq_t.count(s[l])==0)||(freq_s[s[l]]>freq_t[s[l]]))
    {
        freq_s[s[l]]--;
        if(freq_s[s[l]]==0)
            freq_s.erase(s[l]);
        l++;
    }
    if((resr-resl+1)>(r-l+1))
        {
            resl=l;
            resr=r;
        }
}
cout<<s.substr(resl,(resr-resl+1));
return 0;

}

i’m getting a run error in test case 2 and 7

@rohitkv090 look at the output format you have forgot one thing

If no such substring exist then output “No String” without quotes

1 Like

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.