Search
 
SCRIPT & CODE EXAMPLE
 

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Jython Java Python 
Cpp :: set app icon qt 
Cpp :: C++ Vector Initialization method 02 
Cpp :: compile c++ program 
Cpp :: c++ code 2d block 
Cpp :: ue4 c++ oncomponentbeginoverlap 
Cpp :: can derived class access base class non-static members without object of the base class 
Cpp :: map update field elixir 
Cpp :: 2d stl array 
Cpp :: 2160. Minimum Sum of Four Digit Number After Splitting Digits leetcode solution in c++ 
Cpp :: Codeforces Round #376 (Div. 2), problem: (A) Night at the Museum 
Cpp :: 1603. Design Parking System leetcode solution in c++ 
Cpp :: object as a function argument and returning object 
Cpp :: Lapindromes codechef solution in c++ 
Cpp :: c++ sort a 2d vector by column 
Cpp :: hello command not printing in c++ 
Cpp :: operator overloading 
Cpp :: how to pass arrays by reference c++ 
Cpp :: Determine if map contains a value for a key c++ 
Cpp :: template function in class c++ 
Cpp :: math in section latex 
Cpp :: call by value in c++ 
Cpp :: is the c++ 20 char te same as the old one 
C :: how to remove button decoration 
C :: golang loop through array 
C :: get window width height glfw 
C :: lerp function c 
C :: successeur nombre chaine 
C :: silicon valley 
C :: divide and conquer program in c 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =