Why is this not right?

#include
#include<unordered_map>
#include
using namespace std;

int main()
{ int a=99999;
int b=-1;
int comp=99999;
int ax,bx=0;
string ip;
getline(cin,ip);
char arr[ip.length()+1];
int j=0;
for(int i=0;i<ip.length();i++)
{
if(ip[i]!=’ ')
{
arr[j++]=ip[i];
}

}
arr[j]='\0';
string x=arr;




string y;
getline(cin,y);
unordered_map<char,int> m;
int ctr=0;
for(int i=0;i<y.length();i++)
{
	if(y[i]!=' ')
	{	ctr++;
		m[y[i]]=-1;
	}
}

for(int i=0;i<x.length();i++)
{
	if(x[i]!=' ')
	{	auto it=m.find(x[i]);
		if(it!=m.end())
		{	if(m[x[i]]==-1)
			{
			ctr--;
			}
			m[x[i]]=i;
			
		}
		if(ctr==0)
		{	int min=999,max=-1;
			for(auto it=m.begin();it!=m.end();it++)
			{	
				if((*it).second<min)
				{
					min=(*it).second;
				}
				if((*it).second>max)
				{
				max=(*it).second;
				}
			}
				comp=(comp>(max-min))?(max-min):comp;
				if(comp==max-min)
				{
					a=min;
					b=max;
				}
		}
	}
}
	
	

for(int i=a;i<=b;i++)
{
	cout<<x[i];
}

if(ctr!=0)
{
	cout<<"No string"<<endl;
}

}

please explain your approach, how your trying to adjust the window?

i removed all the spaces from string1

then I created a map of all charachters of string2 ignoring whitespaces and initialised all values with -1, After that I iterarated over string1 and updated the value of the map with index of charachter match

after that I computed the length of the window by computing difference bw min and max vlues of indexes in the map, and if it is shorter than pevious, I updated a,b which are points in original string and thus give output

Your code is not working fine.
Take some cases where your string2 has some repeated chars for eg :- fasfdadad and fasf.

Also why are you removing the spaces. if the inputs are like:-
for eg:- “fas fdadad” and “fas f”

So, analyze these cases and come up with a solution that covers all the cases.

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.