Given two unsorted arrays: a[] and b[], where both arrays contain distict elements, check if array b is a subset of array a.
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'.
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)
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);