-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy patharray subset of another array
64 lines (56 loc) · 1.42 KB
/
array subset of another array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Given two arrays: arr1[0..m-1] of size m and arr2[0..n-1] of size n. Task is to check whether arr2[] is a subset of arr1[] or not. Both the
arrays can be both unsorted or sorted. It may be assumed that elements in both array are distinct.
Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an two
integers m and n denoting the size of arr1 and arr2 respectively. The following two lines contains the space separated elements of arr1 and
arr2 respectively.
Output:
Print "Yes"(without quotes) if arr2 is subset of arr1.
Print "No"(without quotes) if arr2 is not subset of arr1.
Constraints:
1 <= T <= 100
1 <= m,n <= 105
1 <= arr1[i], arr2[j] <= 105
Example:
Input:
3
6 4
11 1 13 21 3 7
11 3 7 1
6 3
1 2 3 4 5 6
1 2 4
5 3
10 5 2 23 19
19 5 3
Output:
Yes
Yes
No
Explanation:
Testcase 1: (11, 3, 7, 1) is a subset of first array.
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
int t; cin>>t; while(t--){
ll n,m; cin>>n>>m;
ll x,flag=0;
vector<ll> a;
vector<ll> b;
map<ll, int> ma;
for(int i=0; i<n; i++) { cin>>x; a.push_back(x); ma[a[i]]++; }
for(int i=0; i<m; i++) { cin>>x; b.push_back(x); }
for(int i=0; i<m; i++){
if(ma[b[i]] == 0)
{
flag=1;
break;
}
}
if(!flag) cout<<"Yes\n";
else cout<<"No\n";
}
}