Skip to content

Practice Intersection of Multiple Arrays

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2248
LeetCode Problem

Intersection of Multiple Arrays

Problem Statement

Return the integers that occur in every row of nums, sorted from smallest to largest. Rows are nonempty and contain distinct positive values. If no value is common to all rows, return an empty array. Practice approach: Count how many rows contain each value, or repeatedly intersect a candidate set with the next row. Because a row contains no duplicate values, a frequency equal to the number of rows identifies a common value. Sort the final candidates. For T input values and u common values, counting plus sorting takes O(T + u log u) time.

Source: Intersection of Multiple Arrays on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]
Output
[3,4]

# Example 2

Input
nums = [[1,2,3],[4,5,6]]
Output
[]

Constraints

1 <= nums.length <= 1000
1 <= sum(nums[i].length) <= 1000
1 <= nums[i][j] <= 1000
All the values of nums[i] are unique.

Related LeetCode Problems

Practice more problems similar to Intersection of Multiple Arrays.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.