title: Codechef-Chef and his Sequence
body: <p>I am trying a solution for the below problem.</p>
  
  <p>link to the problem:<a href="https://www.codechef.com/problems/CHEFSQ" rel="nofollow">problem link</a></p>
  
  <p><strong>Problem</strong>:
  Chef has a sequence of N numbers. He like a sequence better if the sequence contains his favorite sequence as a substring.</p>
  
  <p>Given the sequence and his favorite sequence(F) check whether the favorite sequence is contained in the sequence</p>
  
  <p>Input</p>
  
  <p>The first line will contain the number of test cases and are followed by the cases. 
  Each test case consists of four lines: The length of the sequence, the sequence N,the length of F and the sequence F</p>
  
  <p>Output</p>
  
  <p>Print "Yes" if the sequence contains the favourite sequence int it otherwise print "No".</p>
  
  <p>However,I am getting wrong answer.Look into my code        </p>
  
  <p><strong>Code</strong>:</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  int check(int *p,int *q,int n,int m)
  {
      int i,j,l;
      for(i=0;i&lt;n;i++)
      {
          if(p[i]==q[0])
          {
              j=i;
              for(l=0;l&lt;m;l++)
              {
                  if(q[l]==p[j])
                      j++;
                  else
                      break;
              }
          }
          if(l==m)
              return 1;
      }
      return 0;
  }
  int main(void)
  {
      int a,*p,*q,m,t,i,n;
      cin&gt;&gt;t;
      while(t--)
      {
          cin&gt;&gt;n;
          p=new int[n];
          for(i=0;i&lt;n;i++)
              cin&gt;&gt;p[i];
          cin&gt;&gt;m;
          q=new int[m];
          for(i=0;i&lt;m;i++)
              cin&gt;&gt;q[i];
          if(check(p,q,n,m)==1)
              cout&lt;&lt;"Yes"&lt;&lt;endl;
          else
              cout&lt;&lt;"No"&lt;&lt;endl;
      }
      return 0;
  }
  </code></pre>