DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Array

Intersection of Two Arrays II

**Problem Statement:** Given two integer arrays `nums1` and `nums2`, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order. **Hint / Expected Approach:** Hash map frequency count **Edge Cases to Consider:** - (1) One array is empty - (2) No common elements - (3) All elements identical in both

Examples

Example 1
Input: [1, 2, 2, 1], [2, 2]
Output: [2, 2]
Example 2
Input: [4, 9, 5], [9, 4, 9, 8, 4]
Output: [4, 9]
Example 3
Input: [1], [1]
Output: [1]

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪One array is empty
  • ▪No common elements
  • ▪All elements identical in both
Frequently Asked At
GoogleAmazonAdobeInfosys