My code getting wrong answer and please try to answer quickly

#include<bits/stdc++.h>
using namespace std;
#define INT_MAX 100007
string find_ans(string s,string p)
{
int sl=s.length();
int pl=p.length();
if(pl>sl)
{
return “No String”;
}
int fs[256]={0};
int fp[256]={0};
// forming the pattern array with index
for(int i=0;i<pl;i++)
{
char ch=p[i];
fp[ch]++;
}
int cnt=0;
int start=0;
int min_len=INT_MAX;
int start_idx=-1;
for(int i=0;i<sl;i++)
{
char ch=s[i];
fs[ch]++;
if(fp[ch]!=0 and fs[ch]<=fp[ch])
{
cnt++;
}
if(cnt==pl)
{
// now you are ready to shrink the array
char temp=s[start];
// matlab pattern mn nahin hai sirf fs mn h
while(fp[temp]==0 or fs[temp]>fp[temp])
{
fs[temp]–;
start++;
temp=s[start];
}
int window_len=i-start+1;
if(window_len < min_len)
{
min_len=window_len;
start_idx=start;
}

	}
}
if(start_idx==-1)
{
	return "No String";
}
string ans=s.substr(start_idx,min_len);
return ans;

}
int main()
{
string s,p;
getline(cin,s);
getline(cin,p);
cout<<s<<" "<<p<<endl;
cout<<find_ans(s,p)<<endl;
}
//string s;
//cin>>s;
//cout<<s;
//// snnsdfey kuft input
////output is snnsdfey
//but i want the output as
//// snnsdfey kuft

please reply as soon as posible

But it works on different ide perfectly

Please paste the code in an online ide and share the link, from next time.

Please note that, INT_MAX is a predefined constant, not only can it generate error in most compilers, but also it is not recommended.

So use INF or some other variable name for this.

I see no other issue as of now.

1 Like