Just take reverse of any one of the strings and compare the rest and the string which is reversed.
Theta(n) + Theta(n) = 2 * Theta(n) = Theta(n)
Anonymous
27 Dec 2010
I provided algorithm with O(n2) complexity. They he asked for optimizing it for speed. I gave another algorithm with O(nlogn) that involves mergesort of individual strings and then one-to-one comparison. Everyone can have their own algorithms and he wanted me provide algorithm as he had in his mind... he kept asking for O(n) solution that i could not completely provide in given amount of time...
Anonymous
29 Jan 2011
char *str = "civic";
char* begin = str;
char* end = str + strlen(str) - 1;
int is_palindrome = 1;
while ( begin < end ) {
if ( to_upper(*begin) == to_upper(*end))
continue;
else
{
is_palindrome = 0; break;
}
}