851. Check if Array is Subset of Another

You are given two arrays arr1[] and arr2[], and you need to determine whether arr1[] is a subset of arr2[].

An array is considered a subset of another if every element of arr1[] exists in arr2[].

Example 1:

Input: arr1 = [1, 3, 4, 5, 2], arr2 = [2, 4, 3, 1, 7, 5, 15]

Output: true

Explanation: All elements of arr1 are present in arr2.

Example 2:

Input: arr1 = [1, 3, 4, 5, 2], arr2 = [4, 5, 2]

Output: false

Explanation: Elements like 1 and 3 are missing from arr2.

Now Your Turn!

Pick the correct output for the given input

Input: arr1 = [99, 1000, 500], arr2 = [1000, 500, 99, 3000]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= arr1.length <= 105
  • 1 <= arr2.length <= 105
  • 1 <= arr1[i], arr2[i] <= 109
0
class Solution {
public:
bool isSubset(vector<int>& arr1, vector<int>& arr2) {
// Your code goes here
}
};
Test Case

Input:

Arr1
Arr2