Design Gurus Logo
Intersection of Two Arrays (easy)

Problem Statement

Given two arrays, nums1 and nums2 containing integers, return an array of the intersection of nums1 and nums2. In the resultant array, each integer should be unique, and elements can be in any order.

Examples

  • Example 1:

    • Input: nums1 = [3,1,2,6,7,8], nums2 = [2,3,4,5,7,9]
    • Expected Output: [2,3,7]
    • Justification: The numbers 2, 3, and 7 are present in both nums1 and nums2.
  • Example 2:

    • Input: nums1 = [1,2,3], nums2 = [4,5,6]
    • Expected Output: []
    • Justification: There are no common elements between nums1 and nums2, hence the output is an empty array.
  • Example 3:

    • Input: nums1 = [7,8,9,10], nums2 = [10,9,8,7]
    • Expected Output: [7,8,9,10]
    • Justification: All elements from nums1 are present in nums2 and vice versa.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory