Return Distinct Values Shared by Two Arrays

Quick Overview

Return Distinct Values Shared by Two Arrays. Return every value that appears in both nums1 and nums2, exactly once. The source accepts any output order.

Return Distinct Values Shared by Two Arrays

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return every value that appears in both nums1 and nums2, exactly once. The source accepts any output order. ```cpp vector<int> intersection(vector<int>& nums1, vector<int>& nums2); ``` ### Examples ```text nums1=[3,3,5,7], nums2=[7,3,7] -> [3,7] nums1=[1], nums2=[2] -> [] ``` ### Constraints - Each length is 1 through 1000. - Values lie in [0,1000]. ### Follow-up Questions Explain how the permitted output freedom is preserved without losing required values or occurrences. ### What a Strong Answer Covers Mark presence in the first array and clear a mark when it is emitted during a scan of the second. Explain why every produced result satisfies the source contract and why no required result is omitted.

Overview: Return Distinct Values Shared by Two Arrays. Return every value that appears in both nums1 and nums2, exactly once. The source accepts any output order.

Google logo
Google
Sep 22, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return every value that appears in both nums1 and nums2, exactly once. The source accepts any output order.

vector<int> intersection(vector<int>& nums1, vector<int>& nums2);

Examples

nums1=[3,3,5,7], nums2=[7,3,7] -> [3,7]
nums1=[1], nums2=[2] -> []

Constraints

  • Each length is 1 through 1000.
  • Values lie in [0,1000].

Follow-up Questions Guidance

Explain how the permitted output freedom is preserved without losing required values or occurrences.

What a Strong Answer Covers Guidance

Mark presence in the first array and clear a mark when it is emitted during a scan of the second. Explain why every produced result satisfies the source contract and why no required result is omitted.