Problem, as an interviewer would state it:
"Write isSubset(sub, sup) that returns whether every element of sub appears in sup. Discuss edge cases, runtime, and what subset should mean when there are duplicates."
Examples:
isSubset([1, 2], [3, 2, 1]); // true
isSubset([1, 4], [1, 2, 3]); // false
Clarifying questions expected:
- Set semantics (only presence matters) or multiset semantics (counts matter, so
[1,1]is not a subset of[1])? - Is the empty array a subset of everything?
- How are
NaN, objects, and1versus"1"compared?
Code / implementation expected: Yes — real, direct proof against a brute-force reference, in both semantics.