dsa · easy

Intersection of Two Arrays II

Return the multiset intersection of nums1 and nums2: a value that appears a times in the first and b times in the second appears min(a, b) times in the result. Order does not matter.

Arguments

Example

nums1 = [1,2,2,1], nums2 = [2,2][2,2].

Constraints

1 <= nums1.length, nums2.length <= 1000 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[1,2,2,1]
[2,2]

Expected:
[2,2]

Example 2

Input:
[4,9,5]
[9,4,9,8,4]

Expected:
[4,9]

Open in the Dojo editor