Intersection of Multiple Arrays - Problem
Given a 2D integer array nums where nums[i] is a non-empty array of distinct positive integers, return the list of integers that are present in each array of nums sorted in ascending order.
Each sub-array contains only distinct positive integers, and we need to find the intersection of all arrays - the numbers that appear in every single array.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]
›
Output:
[3,4]
💡 Note:
Numbers 3 and 4 appear in all three arrays: [3,1,2,4,5] contains 3,4; [1,2,3,4] contains 3,4; [3,4,5,6] contains 3,4
Example 2 — Single Element
$
Input:
nums = [[1,2,3],[4,5,6]]
›
Output:
[]
💡 Note:
No numbers appear in both arrays - first array has [1,2,3] and second has [4,5,6] with no overlap
Example 3 — All Same
$
Input:
nums = [[1,2,3,4,5],[1,2,3,4,5]]
›
Output:
[1,2,3,4,5]
💡 Note:
Both arrays are identical, so all elements [1,2,3,4,5] appear in every array
Constraints
- 1 ≤ nums.length ≤ 1000
- 1 ≤ nums[i].length ≤ 1000
- 1 ≤ nums[i][j] ≤ 1000
- All the values of nums[i] are unique
Visualization
Tap to expand
Understanding the Visualization
1
Input
Multiple arrays with distinct elements
2
Process
Find elements present in ALL arrays
3
Output
Sorted list of common elements
Key Takeaway
🎯 Key Insight: Count frequency of each number - elements in intersection appear exactly once per array
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code