Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Find all common numbers in given three sorted arrays.

Objec­tive: Given three sorted(ascending order) arrays of inte­gers, find out all the com­mon ele­ments in them.

Input: Three sorted arrays.

Out­put: All the com­mon elements.

Exam­ples :

Array A = {1,2,3,4,5,6,7,8,9,10};
Array B = {1,3,5,6,7,8,12};
Array C = {2,3,4,5,8,9};
Common Elements are 3,5,8


  • Very Sim­ple Solution.
  • Nav­i­gate all three arrays(A,B,C) simul­ta­ne­ously using indexes say, i,j,k.
  • if(A[i]==B[j]==C[k]) then print A[i] and do i++, j++, k++.
  • if not then com­pare all A[i],B[j],C[k] and which ever is smaller, increase its index.
  • Stop when any of these array gets over

Com­plete Code:


Common Elements are : 3 5 8

You may also like...