Search⌘ K
AI Features

Solution: Intersection of Two Arrays II

Explore solving the intersection of two integer arrays by building a frequency map with hash maps. Learn to efficiently collect common elements appearing in both arrays exactly as many times as they occur.

Statement

Given two integer arrays nums1 and nums2, return an array representing their intersection. Each element in the result should appear exactly as many times as it appears in both arrays. The result may be returned in any order.

Constraints:

  • 11 \leq nums1.length, nums2.length 1000\leq 1000 ...