Problem, as an interviewer would state it: "Given two arrays, return their union — every element that appears in either array, with no duplicates. Then tell me how you'd generalize it to more than two arrays."
Examples:
union([1,2,3], [2,3,4]) -> [1,2,3,4]
Clarifying questions expected:
- Does the output order matter — first-seen order, sorted, or unspecified?
- Are the inputs guaranteed to be primitives, or could they contain objects (where equality gets more subtle)?
- Should this generalize to more than two input arrays from the start, or is two enough for a first pass?
Code / implementation expected: Yes — real, direct proof that a Set-based approach produces identical results to, and is measurably faster than, a brute-force .includes()-based version.