Monday, July 17, 2006

First repeating element

/*
How will u find the first repeating letter in a string?... Remember solution should be efficient in both time and space...

Example:
abcdabccccaab
Reapeating letters are: a, b, c
take an auxilary array of 256 ...O(n) complixity in time also
*/

#define MAX 500
int main()
{
char arr[MAX],aux[256];
int i,j;
for(i=0;i lessThan 256;i++)
aux=0;
scanf("%s",arr);

for(i=0;i lessThan j;i++)
if(aux[arr[i]])
{
printf("The repeting character is %c",arr);
break;
}
else
aux[arr[ i]]++;
return ;
}

No comments: