Pergunta de entrevista da empresa NetApp

Check if 2 strings are palindrome?

Respostas da entrevista

Sigiloso

27 de dez. de 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...

Sigiloso

19 de jan. de 2011

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)

Sigiloso

29 de jan. de 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; } }

1