Close
Topic list
Common Elements In Three Sorted Arrays
MEDIUM
35 mins
Binary Search
Topics (Covered in this problem)
Problem solved
Skill meter
Binary Search
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Common Elements In Three Sorted Arrays

Contributed by
Vishal Modani
Medium
0/80
Avg time to solve 35 mins
Success Rate 65 %
Share

## Problem Statement

#### Note:

``````1. The output array should have the same ordering of elements as the original arrays.
2. Even if a particular element appears more than once in each of the three arrays, it should still be present only once in the output array.
3. If there are no common elements in the arrays, return an empty array.
``````

#### For example:

``````Consider the three arrays A = [ 2, 3, 4, 7 ] , B = [ 0, 0, 3, 5 ] , C = [ 1, 3, 8, 9 ]
The output array should be [ 3 ] as 3 is the only element which is present in all the three arrays.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )

#### Sample Input 1:

``````2
4 3 3
1 4 5 6
3 4 5
5 6 7
3 1 3
4 6 8
6
2 2 6
``````

#### Sample Output 1:

``````5
6
``````

#### Explanation for Sample Input 1:

``````For the first test case :
Elements that are common in array A and B = [ 4, 5 ]. Out of which only 5 is present in Array C. Therefore the output array is [ 5 ] in this case.

For the second test case :
It can be seen that only 6 is present in all the three arrays. Therefore the output array is [ 6 ] in this case.
``````

#### Sample Input 2:

``````2
4 4 3
1 2 2 3
2 2 3 3
2 2 3
3 2 2
1 2 3
0 6
4 6
``````

#### Sample Output 2:

``````2 3
``````

#### Explanation for Sample Input 2:

``````For the first test case, elements 2,3 are present in all three arrays.
For the second test case, no element is common in all three arrays, hence we do not print anything.
``````
Auto
Console