Array Subset

Given two unsorted arrays: a[] and b[], where both arrays contain distict elements, check if array b is a subset of array a.

Hint

Create a hash set containing all the elements from set 'a'. Then, iterate through each element in set 'b' and check if that element is present within the hash set created from set 'a'.

# Python implementation
a = [11, 7, 1, 13, 21, 3]
b = [11, 1, 7]

hash = set(a)

result = True

for i in b:
  if i not in hash:
    result = False
    break

print(result)
// Javascript implementation
const a = [11, 7, 1, 13, 21, 3];
const b = [11, 1, 7];

const hash = new Set(a);

let result = true;

for (let i of b) {
  if (!hash.has(i)) {
    result = false;
    break;
  }
}

console.log(result);