This is Discussion thread about Form A New String
Discussion About Form A New String
`#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
string s,t;
cin>>s>>t;
int ls=s.length();
int lt=t.length();
int count=1;
int j=0;
for(int i=0;i<lt;i++)
{
int r=j;
while(s[j]!=t[i])
{
j++;
if(j==ls)
{
j=0;
count++;
}
else if(j==r)
{
cout<<"-1\n";
return 0;
}
}
j++;
if(j==ls)
{
j=0;
count++;
}
}
cout<<count<<"\n";
return 0;
}`
How to reduce time complexity of this solution? It is exceeding time for a test case.