Longest Palindrome:

This question revolves around analyzing a string to determine the longest possible palindrome that can be construed.

A palindrome is simply a word or phrase that produces the same order of letters if read from left or right.

The question involves only finding any single one of the longest palindromes creatable.

Given an arbitrary string, print one of the longest palindromes achievable.

Approach 1:

My first approach was terribly cluttered. I would count each letter, store it in a dictionary, along side a sum of the number of times it was seen. Then, iterate through the dictionary subracting one from each odd number discovered past the first (this odd number can span the center of the result, and is the only odd-number that can occur in a palindrome). Finally, print half the letters forwards, print the odd character, and print half the letters backwards.

As you can probably imagine, this was overkill in the extreme, and added a lot of unecessary complexity - perhaps useful to iterate through all possible combinations, but largely unecessary for the question as asked.

I wrote code for about 30 minutes, made several significant revisions... in the end I was still walking through examples when time ran out.

Immediately upon hanging up, the stress of the event gone, I wrote this simpler version, spending maybe 5 minutes on it. =/

Enter in a string of characters or numbers, then step through the processing, or simply hit "PLAY"

Input text:

Slow
Fast
uninitialized:null
uninitialized:null
uninitialized:null
uninitialized:null
uninitialized:null
uninitialized:null
uninitialized:null

static string FindPalindrome(string input)
{
    char[] tempString = new char[input.Length];
    HashSet<char> tracker = new HashSet<char>();
    int insertPosition = 0;
    for (int i = 0; i < input.Length; i++)
    {
        if (tracker.Contains(input[i]))
        {
            tracker.Remove(input[i]);
            tempString[insertPosition] = input[i];
            tempString[(tempString.Length - insertPosition) - 1] = input[i];
            insertPosition++;
        }
        else
        {
            tracker.Add(input[i]);
        }
    }
    if (tracker.Count > 0)
    {
        tempString[insertPosition] = tracker.ToArray()[0];
    }
    StringBuilder outputBuilder = new StringBuilder();
    for (int x = 0; x < tempString.Length; x++)
    {
        if (tempString[x] != 0)
        {
            outputBuilder.Append(tempString[x]);
        }
    }
    return outputBuilder.ToString();
}