Hi,

Could someone tell me if there's a better way of doing this? I was asked this question in an interview and I wrote a piece of code of O(n2).

Code:
// This function returns a new string of the common alphabets found in a and b
char* intersection(char*a, char* b)
{
   static char temp[20];
   int i = 0;
   if ( (a==NULL) || (b==NULL))
        exit(0);
   else
    {
         while ( a != NULL)
         {
               if(strchr(b, *a))
               {
                    temp[i] = *a;
                    i++;
                    a++;
               }
         }  
    }

    return temp;
}
Thanks,
Tina

Last edited by shabbir; 22Jul2009 at 21:50.. Reason: Code blocks