# Intersection Of Two Sorted Arrays

Contributed by
Sakshi Bansal
Last Updated: 23 Feb, 2023
Easy
0/40
Avg time to solve 10 mins
Success Rate 90 %
Share

## Problem Statement

#### Intersection of two arrays is an array that consists of all the common elements occurring in both arrays.

##### Note :
1. The length of each array is greater than zero.
2. Both the arrays are sorted in non-decreasing order.
3. The output should be in the order of elements that occur in the original arrays.
4. If there is no intersection present then return an empty array.
Detailed explanation ( Input/output format, Notes, Images )
##### Constraints :
1 <= T <= 100
1 <= N, M <= 10^4
0 <= A[i] <= 10^5
0 <= B[i] <= 10^5

Time Limit: 1 sec
2
6 4
1 2 2 2 3 4
2 2 3 3
3 2
1 2 3
3 4
2 2 3
3
##### Explanation for Sample Input 1 :
For the first test case, the common elements are 2 2 3 in both the arrays, so we print it.

For the second test case, only 3 is common so we print 3.
2
3 3
1 4 5
3 4 5
1 1
3
6
4 5
-1
Autocomplete
Console