Intersection of Multiple Arrays
1 approach, code in every language
Problem description
You are given a two-dimensional array nums of positive integers. Every inner array contains a set of distinct values (no duplicates within a single inner array).
Return a sorted list, in ascending order, of the integers that appear in every inner array of nums.
If no integer is present in all of the inner arrays, return an empty list.
Example 1
Input: nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]
Output: [3,4]
Only 3 and 4 appear in all three inner arrays, so the sorted intersection is [3,4].
Example 2
Input: nums = [[1,2,3],[4,5,6]]
Output: []
No value is shared between the two inner arrays, so the result is empty.
Constraints
1 <= nums.length <= 10001 <= sum(nums[i].length) <= 10001 <= nums[i][j] <= 1000All values within each nums[i] are distinct
Create a free account to see the solution
You get the step-by-step animation, the intuition and clean code in every language. Free, no credit card.
After the pattern
Now solve one you haven't seen.
Reading a pattern isn't the same as using it. The practice set has 1,194 original problems on the same techniques, each graded in your browser.
1,194 problems · 15,062 graded tests · free