Distinct Values Exclusive to Each of Two Arrays

Quick Overview

Distinct Values Exclusive to Each of Two Arrays. Return a two-list result: the first contains distinct values present in nums1 but absent from nums2, and the second contains distinct values present in nums2 but absent from nums1. The order inside each list is unrestricted; the two list roles stay fixed.

Distinct Values Exclusive to Each of Two Arrays

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return two lists for the integer arrays `nums1` and `nums2`. The first must contain every distinct value that occurs in `nums1` but not in `nums2`; the second must contain every distinct value that occurs in `nums2` but not in `nums1`. Values may appear in any order within a list, but the two lists must retain these respective roles. ```cpp class Solution { public: vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2); }; ``` ### Examples **Example 1:** ```text nums1 = [0,0,2], nums2 = [2,3,3] Output: [[0],[3]] Explanation: Repeated exclusive values are emitted only once. ``` **Example 2:** ```text nums1 = [4,5], nums2 = [5,4] Output: [[],[]] Explanation: Both arrays have the same set of values. ``` ### Constraints - Both lengths lie in `[1,1000]`. - All values lie in `[-1000,1000]`. ### Clarifying Questions Differences are set differences, not frequency differences. Only inner-list order is free. ```hint Inspect the structure Why must multiplicity be discarded before emitting exclusive values? ``` ### What a Strong Answer Covers - Include values according to presence in one input and absence from the other, irrespective of frequency. - Emit each qualifying value only once and preserve the fixed roles of the two result lists. - Allow either inner order and handle equal value sets or an empty result side. ### Follow-up Questions Could the small bounded value domain simplify membership tracking?

Overview: Distinct Values Exclusive to Each of Two Arrays. Return a two-list result: the first contains distinct values present in nums1 but absent from nums2, and the second contains distinct values present in nums2 but absent from nums1. The order inside each list is unrestricted; the two list roles stay fixed.

Bloomberg logo
Bloomberg
May 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return two lists for the integer arrays nums1 and nums2. The first must contain every distinct value that occurs in nums1 but not in nums2; the second must contain every distinct value that occurs in nums2 but not in nums1. Values may appear in any order within a list, but the two lists must retain these respective roles.

class Solution {
public:
    vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2);
};

Examples

Example 1:

nums1 = [0,0,2], nums2 = [2,3,3]
Output: [[0],[3]]
Explanation: Repeated exclusive values are emitted only once.

Example 2:

nums1 = [4,5], nums2 = [5,4]
Output: [[],[]]
Explanation: Both arrays have the same set of values.

Constraints

  • Both lengths lie in [1,1000] .
  • All values lie in [-1000,1000] .

Clarifying Questions Guidance

Differences are set differences, not frequency differences. Only inner-list order is free.

What a Strong Answer Covers Guidance

  • Include values according to presence in one input and absence from the other, irrespective of frequency.
  • Emit each qualifying value only once and preserve the fixed roles of the two result lists.
  • Allow either inner order and handle equal value sets or an empty result side.

Follow-up Questions Guidance

Could the small bounded value domain simplify membership tracking?