Finding Common Alphabet Between Two Names.

We have two names, say “AMITABH BACHCHAN ” and “RAJNIKANTH”. Our work is find common alphabet in these two names. The answer would be ‘AITHN’. i have written my code, if you find your code, more easier than mine, please do write in comment box. So lets go!

If you are looking for the solution in C/C++. Please visit Here .

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace commonAlpha
    class Program
        static void Main(string[] args)
            char[] name1 = {'A','M','I','T','A','B','H','B','A','C','H','C','H','A','N'};
            char[] name2 = { 'R', 'A', 'J', 'N', 'I', 'K', 'A', 'N', 'T', 'H' };
            StringBuilder s1 = new StringBuilder();
            for (int i = 0; i<name1.Count(); i++)
                for (int j = 0; j < name2.Count(); j++)
                    //compareing two char from both string
                    if (name1[i] == name2[j])
                        char temp = name2[j];
                        if (s1.Length != 0)
                            int flag = 0;
                            //checking whether its already in s1 or not. If yes, flag will be greater than 0 or if not flag=0
                            for (int k = 0; k < s1.Length; k++)
                                if (s1[k] == temp)
                            //confirm that temp is not in s1
                            if (flag == 0)
            for (int i = 0; i < s1.Length; i++)

Copyright © 2013 ·All Rights Reserved · Republishing or copying this article or any part of this without giving reference would come under WordPress Copyright Act.

If you liked this article, please rate and comment. Thank You!


Deepesh Singh
You may also like.

Windows 8 App Store Internet on Windows Phone Influence of Online Social Networks C Program

13 thoughts on “Finding Common Alphabet Between Two Names.

  1. Add the PHP tags for the below code..
    echo “The common alphabets in the two names are: “;
    $result=array_unique(array_intersect($arr1, $arr2));
    echo implode($result);

  2. for java ::

    public class checking {

    public static void main(String[] s){
    checking ck=new checking();
    String s1=”AMITABH BACHCHAN”;
    String s2=”RAJNIKANTH”;
    char[] ch1=s1.toCharArray();
    char[] ch2=s2.toCharArray();
    StringBuilder sb=new StringBuilder();

    for(int i=0; i<ch1.length;i++){
    for(int j =0;j<ch2.length;j++){
    int cflag =0; // here to reset again
    char c=ch1[i];
    for(int k =0; k<sb.length();k++){




Please leave your valuable comment.

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s