xml-blog xml-blog I am what I am and that's all that I am.

Niner since 2004

I am what I am and that's all that I am.


  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    bool CheckPalindrome (string CheckString)
        if (null == CheckString || 0 == CheckString.Length) return false;
        for (int i = 0; i < CheckString.Length / 2; i++)
            if (CheckString[i] != CheckString[CheckString.Length - 1 - i]) return false;
        return true;

    My goals were to keep the algorithm short and simple and to support a majority of common scenarios. Things not taken into account include treating spaces or accented characters in a special way, just to name two. My contribution to this thread is that a conditional statement for the odd/evenness of a string is unnecessary because the integer division will always return an integer (leaving the remainer to mod). This means in the algorithm above even strings get compared to the last character and  odd strings ignore the mod character. Also, the use of iteration (as opposed to recursion) and array-index lookup make for very fast execution times on the order of O(n).

    P.S. Thanks for the props, ezu: http://channel9.msdn.com/ShowPost.aspx?PostID=19369#19369

    P.S.S. Let's keep this thread interesting - anyone want to take a stab at a palindrome - generating function that uses the entire Unicode character set?

    P.S.S.S. If you like these sorts of problems, check out http://www.topcoder.com