15. Intersection of Two Arrays

15. Intersection of Two Arrays

Easy
50.0%
2.1k
arrayhash-tablesorting
Google, Amazon, Netflix, Meta (Facebook), Apple, Microsoft, Uber, Bloomberg, Airbnb, Stripe, Adobe, Salesforce, LinkedIn, Oracle

You’re interviewing for a backend or data engineering role at a FAANG-level company. The interviewer describes a real product scenario:

A large analytics or data aggregation platform collects datasets from multiple independent sources. Each dataset contains identifiers such as:

  • user IDs
  • product IDs
  • content IDs
  • event IDs

To ensure consistency across systems, the platform needs to identify which identifiers appear in both datasets.

These identifiers are stored as integer arrays nums1 and nums2.
For reporting accuracy, the platform only cares about unique identifiers that exist in both datasets, not how many times they appear.

This is a common practice coding problem for DSA question might ask in Google, Amazon, Netflix, Meta, Apple, Microsoft, Uber, and Bloomberg interviews.

Your Task

Given two integer arrays nums1 and nums2, return an array of their intersection.

Each element in the result must be unique, and the result can be returned in any order.

Input Format

  • nums1: an array of integers
  • nums2: an array of integers

Output Format

  • An array of integers representing the unique intersection of nums1 and nums2

Examples

Example 1:

Input: nums1 = [1,2,2,1] nums2 = [2,2]
Output: [2]

Example 2:

Input: nums1 = [4,9,5] nums2 = [9,4,9,8,4]
Output: [4,9]

Constraints

  • 1 <= nums1.length, nums2.length <= 100,000
  • -10^9 <= nums1[i], nums2[i] <= 10^9
  • Each element in the result must be unique

Loading editor...

[1,2,2,1], [2,2]
[2]

Console Output

Click "Run Code" or "Submit" to see results

Your code will be evaluated by AI with instant feedback