What is the problem with this code?
#include
#include
#include
#include
using namespace std;
int main() {
//Inputs
string s1, s2;
cin.get();
getline(cin, s1);
getline(cin, s2);
if(s1.length()<s2.length()){
cout<<“No String\n”;
return 0;
}
map<char, int> m1,m2; //For storing frequencies for s1 and s2 resp.
//Storing frequencies of s2
for(char a: s2){
m2[a]++;
}
// TWO POINTER METHOD
int l=0, r;
int L, R;
int diff = INT_MAX;
//Storing frequencies of s1
for(r=0; r<s1.size(); r++){
m1[s1[r]]++;
bool good = true; //To chk if it is a good string, i.e. satisfies given conditions or not.
for(auto x: m2){
// x is of type pair<char, int>
if(m1.count(x.first) == 0 || m1[x.first] < x.second){
good = false;
break;
}
}
//string window from l to r isn't a good window
if(!good) continue;
//otherwise, we try to move l forward for every r to minimise the string window
while(l<=r && l<s1.length()){
// if l is not present in s2 or if current window in s1 has higher frequency of l than in s2
if(m2.count(s1[l])==0 || m1[s1[l]] > m2[s1[l]]){
m1[s1[l]]--;
if(m1[s1[l]] == 0) m1.erase(s1[l]);
l++; //Reduce the window size
}
else{
break;
}
}
if(diff > r-l+1){
R = r;
L = l;
diff = R- L + 1;
}
}
if( diff == INT_MAX){
cout<<"No String"<<endl;
return 0;
}
else{
cout<<s1.substr(L, diff);
}
return 0;
}
`