Interview Questions
For some unknown reason, I ended up reading through interview questions/jokes today. I know the real reason I ended up here. We’re having some churn on the team and I’ll be participating in the face to face interviews.
I really enjoyed the “You don’t bury survivors” post. (Answers) Jeff Atwoods write-up is interesting. Actually I think all of this started with a post by Atwood on separating those that can program from those that can’t. Which in turn lead me to this draft paper (pdf).
Here’s my FizzBuzz code. I think I spent maybe 5 minutes from firing up VS to rereading the requirements to make sure I wrote what was assigned. I am assuming the first number to be printed it “1″ and not “0″.
for(int i = 0 ; i < 100 ; )
{
i++;
if ( i % 3 == 0 && i % 5 ==0 )
Console.WriteLine("FizzBuzz");
else if (i % 3 == 0)
Console.WriteLine("Fizz");
else if (i % 5 == 0)
Console.WriteLine("Buzz");
else
Console.WriteLine(i);
}
Another question I have been asked was to write a palidrome finder. I was in a bad mood that day and evaded the request. Obviously, I didn’t get the gig. The gig was writing software for a collections company so my conscience must have been screaming at me. <shrug> Anyway, the solution would look something like this:
static bool IsPalindrome(string palindrome)
{
palindrome = palindrome.Trim().Replace(" ", "").ToLower();
if (String.IsNullOrEmpty(palindrome))
return true;
if ( palindrome.Length == 1 )
return true;
// this could also be done with substring. I think this is more readable.
char[] chars = palindrome.ToCharArray();
if (chars[0] != chars[chars.Length -1])
return false;
return IsPalindrome(palindrome.Substring(1, palindrome.Length - 2));
}
