Problem Description
Teenu has a sequence of N numbers. He like a sequence better if the sequence contains his favorite sequence as a substring.
Given the sequence and his favorite sequence(F) check whether the favorite sequence is contained in the sequence
Input
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
Output
Print ""Yes"" if the sequence contains the favourite sequence int it otherwise print ""No""
Constraints
1<=T<=10
1 1CODING ARENA
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n1,n2,i,f=0,k=0;
scanf("%d",&n1);
int a[n1];
for(i=0;i<n1;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&n2);
int b[n2];
for(i=0;i<n2;i++)
scanf("%d",&b[i]);
for(i=0;i<n1&&k<n2;i++)
{
if(a[i]==b[k])
{
f++;
k++;
if(f==n2)
break;
}
}
if(f>=n2)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
Test Case 1
Input (stdin)2 6 1 2 3 4 5 6 3 2 3 4 6 22 5 6 33 1 4 2 4 15
Expected OutputYes No
Test Case 2
Input (stdin)2 4 1 2 3 4 3 1 2 3 2 1 3 3 1 4 6
Expected OutputYes No
thank you very mutch but you must use while loop for goal the space memory andt time
ReplyDeleteNeed this java program
ReplyDelete