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
aandb. - Output: boolean — whether every element of
ais present inb(under the agreed semantics).
Constraints
- Sizes up to 10^5; O(m + n) expected via hashing.
- Handle empty arrays cleanly (an empty
ais trivially contained).
Example
- a =
[1,2,2], b =[2,1,3]→ true as sets; false with multiplicity (b has only one 2).
asked …