finding substring

i have to find a substring,whether it is present or not. giving a wrong answer on codechef but all possible test cases i could think of are running properly.Please help me out. Thanks in advance!

#include<bits/stdc++.h>
using namespace std;

int main()
{
long long int t,i,n,m,coun;
cin>>t;

while(t--)
{
    cin>>n;
    long int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];

    cin>>m;
    long int b[m];
    for(i=0;i<m;i++)
        cin>>b[i];
    coun=0;
    for(i=0;i<n;i++)
    {
        if(a[i]==b[coun])
            coun++;
        else if(a[i]==b[0])
            coun=1;
        else if(a[i]!=b[coun])
            coun=0;

        if(coun==m)
            break;

    }

    if(coun==m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

return 0;

}

your code fails for this testcase

1

6

3 1 3 1 3 2

4

3 1 3 2

answer is Yes but your code gives No

I think its the “Chef and sequence” question.

See, the Q was poorly worded. The order of elements doesnt matter. You just need to see if the characters of his favourite sequence are present or not, in any order. Also, please post problem link if you want community to help you. People cannot locate that Q just from the name.

Thank you sir for giving me a test case where my code fails.
And sir the question is “Chef and his Sequence” code: “CHEFSQ”.
Thanks for helping me! :slight_smile:

Ya, sorry, chef and sequence. I am not good with names :stuck_out_tongue:

Yes indeed, @vijju123 sir the question is poorly worded. We dont have to search for the perfect substring, it just matters that the characters of the favourite string are present in the same order in the original string.

1.read the substring u wanna search
2.the iterate in the given string from the beg index to begindex+length of substring
3.store this in a string and compare it with substring.return true if it exists