Challenge 1: An Array as a Subset of Another Array

Can you find whether or not a given array is a subset of another array by using a hash table?

Problem statement

Implement the isSubset(int[] arr1, int[] arr2, int size1, int size2) function, which will take two arrays and their sizes as input and check whether or not one array is the subset of the other.

Note: The input arrays do not contain duplicate values.

Input

These are two arrays of integers and their sizes.

Output

true if arr2 is a subset of arr1.

Sample input

arr1 = {9,4,7,1,-2,6,5}
arr2 = {7,1,-2}
size1 = 7
size2 = 3

Sample output

true

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.