-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFind whether an array is a subset of another array
67 lines (53 loc) · 1.64 KB
/
Find whether an array is a 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
65
66
67
//{ Driver Code Starts
//Initial Template for Java
//Initial Template for Java
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG {
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine().trim());
while(t-->0)
{
StringTokenizer stt = new StringTokenizer(br.readLine());
long n = Long.parseLong(stt.nextToken());
long m = Long.parseLong(stt.nextToken());
long a1[] = new long[(int)(n)];
long a2[] = new long[(int)(m)];
String inputLine[] = br.readLine().trim().split(" ");
for (int i = 0; i < n; i++) {
a1[i] = Long.parseLong(inputLine[i]);
}
String inputLine1[] = br.readLine().trim().split(" ");
for (int i = 0; i < m; i++) {
a2[i] = Long.parseLong(inputLine1[i]);
}
Compute obj = new Compute();
System.out.println(obj.isSubset( a1, a2, n, m));
}
}
}
// } Driver Code Ends
//User function Template for Java
class Compute {
public String isSubset( long a1[], long a2[], long n, long m)
{
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(a2[i]==a1[j])
{
break;
}
if(j==n-1)
{
return "No";
}
}
}
return "Yes";
}
}