Problem, as an interviewer would state it:
"Return the values that appear in ALL of N arrays, not just two. Discuss edge cases, runtime, and how the arrays' sizes and order affect performance."
Examples:
intersectAll([1, 2, 3, 4], [2, 4, 6], [4, 2, 9]); // [2, 4]
intersectAll([4, 2, 1], [1, 2, 4]); // [4, 2, 1] (order of the first array)
Clarifying questions expected:
- Should the result contain each value once (set semantics), or respect counts (multiset)?
- Which array's order should the result follow?
- What should zero arguments, one array, or an empty array among the inputs return?
Code / implementation expected: Yes — real, direct proof against a brute-force reference, plus a measurement of how ordering and early exit change the cost.