Return Shared Array Occurrences with Minimum Multiplicity
Quick Overview
Return Shared Array Occurrences with Minimum Multiplicity. Return the multiset intersection of nums1 and nums2: a value occurring a times in the first and b times in the second appears min(a,b) times in the result. Any
Return Shared Array Occurrences with Minimum Multiplicity
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
### Problem
Return the multiset intersection of nums1 and nums2: a value occurring a times in the first and b times in the second appears min(a,b) times in the result. Any output order is allowed.
```cpp
vector<int> intersect(vector<int>& nums1, vector<int>& nums2);
```
### Examples
```text
nums1=[2,2,2,5], nums2=[2,5,5] -> [2,5]
nums1=[4,4], nums2=[4,4,4] -> [4,4]
```
### Constraints
- Each length is 1 through 1000.
- Values lie in [0,1000].
### Follow-up Questions
How can sorted inputs help? Which algorithm suits very unequal sizes? How would you process a disk-resident second array with limited memory?
### What a Strong Answer Covers
Count occurrences in the smaller input, then consume one count for each matching occurrence in the other. Explain why every produced result satisfies the source contract and why no required result is omitted.
Overview: Return Shared Array Occurrences with Minimum Multiplicity. Return the multiset intersection of nums1 and nums2: a value occurring a times in the first and b times in the second appears min(a,b) times in the result. Any
Return Shared Array Occurrences with Minimum Multiplicity
Amazon
Jul 15, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0
Problem
Return the multiset intersection of nums1 and nums2: a value occurring a times in the first and b times in the second appears min(a,b) times in the result. Any output order is allowed.
How can sorted inputs help? Which algorithm suits very unequal sizes? How would you process a disk-resident second array with limited memory?
What a Strong Answer Covers Guidance
Count occurrences in the smaller input, then consume one count for each matching occurrence in the other. Explain why every produced result satisfies the source contract and why no required result is omitted.