Test cases not passing

Most of my test cases are failing , help me debug my code

Please leave a reply to help me solve the problem

You have not written the separate case of “No string”

Sorry , i’m unable to understand what u r trying to say

#include #include #include #include using namespace std; int main() { string s1; string s2; cin>>s1>>s2; map<int,int> length; int i=0; while(s1[i]!=NULL) { if(s1[i]==s2[0]) { length.insert(make_pair(i,-1)); } i++; } if(length.size()==0) { cout<<“No String”; return 0; } else { auto it=length.begin(); int index; while(it!=length.end()) { string s=s1.substr(it->first); int count=1; while(count!=s2.length()) { index=s.find(s2[count]); if(index==string::npos) { length[it->first]=-1; break; } count++; } if(count==s2.length()) { length[it->first]=index; } it++; } } string ans=""; auto it=length.begin(); int l=100000,key=0,final_key; while(it!=length.end()) { if(it->second<l) { l=it->second; final_key=it->first; } it++; } int c=0; for(int j=final_key;c<=length[final_key];j++) { ans=ans+s1[j]; c++; } cout<<ans<<endl; return 0; }

I am not getting ur approach. Pls elaborate it.


You can go through my code.