Be the first user to complete this post

  • 0
Add to List

Find all common numbers in given three sorted arrays.

Objective: Given three sorted(ascending order) arrays of integers, find out all the common elements in them.

Input: Three sorted arrays.

Output: All the common elements.

Examples :

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 Simple Solution.
  • Navigate all three arrays(A,B,C) simultaneously 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 compare all A[i],B[j],C[k] and which ever is smaller, increase its index.
  • Stop when any of these array gets over


Common Elements are : 3 5 8

Also Read: