Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

determining whether a array is a subsequence of another array

 #include<bits/stdc++.h>
using namespace std;
 
bool issub(int a[],int b[],int n,int m){
  
  int j=0;
  for(int i=0;i<n && j!=m;i++){
    if(a[i]==b[j]) 
    {
      j++;
    }
  }
 
  bool x=(j==m)?1:0;
  return x;
 
}
 
int main(){
   int n,m;
   cin>>n>>m;
  int a[n],b[m];
  for(int i=0;i<n;i++){
      cin>>a[i];
  }
  for(int i=0;i<m;i++){
      cin>>b[i];
  }
  if(issub(a,b,n,m)){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
 
  return 0;
}
 
PREVIOUS NEXT
Tagged: #determining #array #subsequence #array
ADD COMMENT
Topic
Name
5+6 =