Check if one array contains all elements of another

Problem Given two arrays, determine whether the second contains all elements of the first. Clarify up front whether "contains all" means as a set or respecting multiplicities.

Input / Output

  • Input: arrays a and b.
  • Output: boolean — whether every element of a is present in b (under the agreed semantics).

Constraints

  • Sizes up to 10^5; O(m + n) expected via hashing.
  • Handle empty arrays cleanly (an empty a is trivially contained).

Example

  • a = [1,2,2], b = [2,1,3] → true as sets; false with multiplicity (b has only one 2).
asked …
LeaderboardSalaryAccount