Pergunta de entrevista da empresa Microsoft

- Given a string, how would you determine if that string contains a palindrome?

Respostas da entrevista

Sigiloso

9 de jan. de 2012

I guess the question is to check if a string is a palindrome the code is fine but it looks like you need to find within the string if there is a palindrome which is more complex problem and it could be solve with a Suffix tree (this for a longest palindrome) but it can work one we find one. http://en.wikipedia.org/wiki/Suffix_tree

Sigiloso

4 de nov. de 2015

The question is if a string contains a palindrome. So I think the best way is to split the string on the basis of space and then check each word that whether its a palindrome or not.

Sigiloso

7 de dez. de 2011

class Palindrome { public static bool IsPalindrome(string value) { int intLen, intStrPartLen; intLen = value.Length - 1; //Cut the length of the string into 2 halfs. intStrPartLen = intLen / 2; for (int intIndex = 0; intIndex <= intStrPartLen; intIndex++) { //intIndex is the index of the char in the front of the string // Check from behind and front for match if (value[intIndex] != value[intLen]) { return false; } //decrease the length of the original string to //test the next char from behind intLen--; } return true; } static void Main(string[] args) { string[] array = { "Civic", "deified", "deleveled", "devoved", "dewed", "Hannah", "kayak", "level", "madam"}; foreach (string value in array) { Console.WriteLine("{0} = {1}", value, IsPalindrome(value)); } Console.ReadLine(); } } }