EasyArrayHash TableCountingSorting

Intersection of Multiple Arrays

LeetCode
1 approach, code in all languages

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 <= 1000
  • 1 <= sum(nums[i].length) <= 1000
  • 1 <= nums[i][j] <= 1000
  • All values within each nums[i] are distinct
You've got the patterns

Patterns get you through the screen. Shipping gets you hired.

FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.

750+ engineers trained · frontend, backend, AWS & AI

August 15 · 0d left
Enroll Now