![]() |
VOOZH | about |
Given two sorted arrays a[] and b[], where each array may contain duplicate elements , return the elements in the intersection of the two arrays. Intersection of two arrays is said to be elements that are common in both arrays. The intersection should not count duplicate elements and the result should contain items in sorted order.
Examples:
Input: a[] = [1, 1, 2, 2, 2, 4], b[] = [2, 2, 4, 4]
Output: [2, 4]
Explanation: 2 and 4 are only common elements in both the arrays.Input: a[] = [1, 2], b[] = [3, 4]
Output: []
Explanation: No common elements.Input: a[] = [1, 2, 3], b[] = [1, 2, 3]
Output: [1, 2, 3]
Explanation: All elements are common
Table of Content
2 4
The idea is based one merge function to merge two sorted arrays.
2 4
Related Articles: