Question d’entretien chez NetApp

Check if 2 strings are palindrome?

Réponses aux questions d'entretien

Utilisateur anonyme

27 déc. 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...

Utilisateur anonyme

19 janv. 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)

Utilisateur anonyme

29 janv. 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