DIY: Intersection of Two Arrays

Solve the interview question "Intersection of Two Arrays" in this lesson.

Problem statement

Given two integer arrays, nums1 and nums2, you will return an array of their intersection. Each element in the result must be unique, and you may return the result in any order.

Constraints

You can assume the following constraints for this problem:

  • 1 <= nums1.size(), nums2.size() <= 1000
  • 0 <= nums1[i], nums2[i] <= 1000

Input

The input will be the two lists of integers. Here is an example of the input:

nums1 = [1,2,3,2,5]
nums2 = [9,2,3,7,1]

Output

The output will be a list of integers that will contain a unique number of integers. This is the output of the input given above:

[2,3,1]

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.