Given two integer arrays
arr1 and arr2
of size
m and n (n <= m)
respectively, write a program to check whether
arr2
is a subset of
arr1
or not.
Problem Note
-
An array
arr2
is a subset of another arrayarr1
, if each element ofarr2
is present inarr1
. - Both the arrays are not in sorted order
- There are no repeated elements in both the arrays. (Think about the solution where repetitions are allowed)
-
Return 1
if
arr2
is a subset ofarr1
, else return 0.
Example 1
Input: arr1[] = [3, 5, 1, 9, 10, 0, 2], arr2[] = [1, 3, 5, 9]
Output: 1
Explanation: All elements of arr2 are present in arr1.
Example 2
Input: arr1[] = [3, 5, 1, 9, 10, 0, 2], arr2[] = [6, 3, 8]
Output: 0
Explanation: Element 6 and 8 of array arr2 are not present in arr1.