Leaderboard
Showing:
Handle Score
@Ibrahim Nash 5725
@blackshadows 5685
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4908
@saiujwal13083 4156
@sanjay05 3762
@marius_valentin_dragoi 3511
@sushant_a 3453
@KshamaGupta 3318
@the_coder95 3302
Complete Leaderboard
Array Subset of another array
Easy Accuracy: 45.48% Submissions: 40117 Points: 2

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.

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Array Subset of another array

Output Window