public static void printCommonElements(int a[], int b[]){
        int aIdx = 0, bIdx = 0;
        int count = 0;
        boolean isMatch = false;
        while(aIdx < a.length && bIdx < b.length){
            count  = 0;
            isMatch = false;
            while(aIdx < a.length-1 && a[aIdx + 1] == a[aIdx])
                aIdx++;
            if(b[bIdx] == a[aIdx]){
                isMatch = true;
                count++;
            }
            while(bIdx <b.length-1 && b[bIdx+1] == b[bIdx]){
                bIdx++;
                if(isMatch)
                    count++;
            }
            for(int  i = 0 ; i < count; i++)
                System.out.print(b[bIdx] + " ");
            aIdx++; bIdx++;
        }
    }