Array Subset of Another Array

TCS NQT Coding Easy

Given two arrays: a1[0..n-1] of size n and a2[0..m-1] of size m, the task is to check whether a2[] is a subset of a1[] or not. Both arrays can be sorted or unsorted.

Examples:

Input: a1 = [11, 1, 13, 21, 3, 7], a2 = [11, 3, 7, 1]

Output: "Yes"

Explanation: All elements of a2 are present in a1.

Input: a1 = [1, 2, 3, 4, 5, 6], a2 = [1, 2, 4]

Output: "Yes"

Explanation: All elements of a2 are present in a1.

Input: a1 = [10, 5, 2, 23, 19], a2 = [19, 5, 3]

Output: "No"

Explanation: Element 3 from a2 is not present in a1.

Constraints

  • 1 ≤ n, m ≤ 105
  • 1 ≤ a1[i], a2[j] ≤ 106