MediumPro challengePythonJavaScriptTypeScript

Array Intersection

ArraysSets

Implement solve(...arrays) that returns the intersection of all provided
arrays — elements present in every array — without duplicates, in the
order they appear in the first array.

Examples

  • solve([1,2,3,4], [2,4,6])[2,4]
  • solve([1,2,3], [2,3,4], [3,5,6])[3]
  • solve([1,2,3])[1,2,3] (only one array → itself, deduplicated)

Sample tests

Test #1Two arrays
Input: [[1,2,3,4],[2,4,6]]
Output: [2,4]
Test #2Three arrays — only 3 is in all
Input: [[1,2,3],[2,3,4],[3,5,6]]
Output: [3]
Test #3Only 7 appears in all three
Input: [[5,6,7],[7,8,9],[7,10,11]]
Output: [7]
Test #4Duplicates in first array — result is deduplicated
Input: [[1,1,2,2],[1,2]]
Output: [1,2]
Test #5One empty → empty intersection
Input: [[1,2,3],[]]
Output: []