Search⌘ K
AI Features

Solution: Intersection of Two Arrays

Explore how to implement an efficient solution to find the unique intersection of two arrays by using hash maps. Understand the algorithm's linear time complexity and how to prevent duplicate entries by tracking elements with a dictionary. This lesson helps you write optimized C++ code for common array intersection problems.

Statement

You are given two integer arrays, arr1 and arr2. Your task is to return a new array containing the intersection of both arrays.

  • Each element in the result must be unique.

  • The order of the elements in the result does not matter.

Constraints

  • 11 \leq arr1.length, arr2.length 1000\leq 1000

  • 00 \leqarr1[i], arr2[i] 1000 ...