O26

Intersection of Two Arrays II

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: ARRAY

Problem Statement & Objective

Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order.

Function Signature (Python)

intersect_arrays(arr1: list[int], arr2: list[int]) -> list[int]

Input & Output Contract

Output Rule:Array representing the multiset intersection.

System Constraints

1 <= nums1.length, nums2.length <= 1000
0 <= nums1[i], nums2[i] <= 1000

Example Execution Walkthrough

nums1 = [1,2,2,1], nums2 = [2,2]
result: [2, 2]

Example Test Scenarios (3)

Example 1
Input:[[1,2,2,3],[2,2]]
Expected Output:[2,2]
Example 2
Input:[[4,9,5],[9,4,9,8,4]]
Expected Output:[4,9]
Example 3: Ayrık
Input:[[1,2,3],[4,5,6]]
Expected Output:[]
Loading Python Editor...
Input Parameters
[
  [
    1,
    2,
    2,
    3
  ],
  [
    2,
    2
  ]
]
Expected Output
[
  2,
  2
]