pranay_teja
9/16/2018 - 7:36 AM

GFG Array Subset of another array

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

// #Hashing #Maps #Problem #GFG
// https://practice.geeksforgeeks.org/problems/array-subset-of-another-array/0
// https://www.geeksforgeeks.org/find-whether-an-array-is-subset-of-another-array-set-1/

bool isSubset(vector<int> a1, vector<int> a2){
    // checks if a2 is a subset of a1
    map< int, bool > m;
    for(int i=0;i<a1.size();i++){
        m[ a1[i] ]=true;
    }
    for(int i=0;i<a2.size();i++){
        if( m[ a2[i] ]!=true ){
            return false;
        }
    }
    return true;
}

int main() {
	int t;
	cin>>t;
	while(t--){
	    int m,n;
	    cin>>m>>n;
	    vector<int> a1(m);
	    vector<int> a2(n);
	    for(int i=0;i<m;i++){
	        cin>>a1[i];
	    }
	    for(int i=0;i<n;i++){
	        cin>>a2[i];
	    }
	    if(isSubset(a1,a2)==true){
	        cout<<"Yes"<<endl;
	    }else{
	        cout<<"No"<<endl;
	    }
	}
	return 0;
}