<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Comment Feed for Channel 9 - Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem/RSS"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 - Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<link></link>
	</image>
	<description>During an interview for a technical position at Microsoft your interviewer might turn to you and ask you to write some code, or work out a problem on the whiteboard.

Here&#39;s a mock whiteboard session to see what an interviewer looks for during that stage of the interview.

This is a question made up for Channel 9 intended to demonstrate what is expected in an interview. There are many possible solutions and the answer is only a sample answer. Keep in mind that&amp;nbsp;Evan Goldring&amp;nbsp;(the interviewee) told us after the camera is off that
 he didn&#39;t answer the question with the best possible solution.

Do you have a better solution? Leave it here! Who knows, maybe a recruiter will email you and ask for your resume. 
</description>
	<link></link>
	<language>en</language>
	<pubDate>Thu, 23 May 2013 09:11:49 GMT</pubDate>
	<lastBuildDate>Thu, 23 May 2013 09:11:49 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[I haven't programmed in a while, but couldnt' the logic be:<br>
<br>
1. Ensure all values are proper (not nulls, right datatypes, etc)<br>
2. Read through string forwards<br>
3. Reverse string<br>
4. If both are identical, you've got your palindrome<br>
<br>
...<br>
<br>
Or is that flawed?<br>
<br>
I'm trying to throw&nbsp;cases at this to see how it would break. Seems to me that it must not be the case, otherwise your 2 guys would have thought of it.<br>
<br>
It also seems like just the kind of thing that a young upstart like me would suggest in an interview, only to have someone like Evan go &quot;no, you haven't considered [x]&quot;...<br>
<br>
I'll happily concede that I haven't considered everything, but the above would take into account everything the original question asked for, unless I heard it wrong <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br>
<br>
edit: btw, the way Evan thought through everything was very good. Made me want to practice this before my onsite <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /><p>posted by Jeremy W</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289752990000000</link>
		<pubDate>Tue, 24 Aug 2004 20:14:59 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289752990000000</guid>
		<dc:creator>Jeremy W</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Many *-style eugenics programs in the United States of America feature the job-interview as one of their primary ways of purifying the white collar work force this country.<br>
<br>
The kid who founded Netscape hipped me to what he calls The Law of Crappy People. This states in summary that people who are crappy tend to hire crappy people.<br>
<br>
None of these remarks have to with Microsoft Corporation or its affiliates, reffering to any specific events thereof. You know what George Bush says about guys like me: we're just &quot;happy&quot; about having the chance to say something negative.<br>
<br>
What I do know from many specific events is that I have actually <i>disappointed</i> people when my efforts in the workplace have been successful. They had the world all figured out and then suddenly here I come to turn their world upside down.<br>
<br>
<br>
<p>posted by rasx</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289753310000000</link>
		<pubDate>Tue, 24 Aug 2004 20:15:31 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289753310000000</guid>
		<dc:creator>rasx</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Here is an example of that function in C# (it is case sensitive):<br>
<br>
<p>private bool CheckPalindrome(string myString)</p>
<p>{</p>
<blockquote dir="ltr">
<p>int First;</p>
<p>int Second;</p>
<p>First = 0;</p>
<p>Second = myString.Length - 1;</p>
<p>while (First &lt; Second)</p>
<p>{</p>
<blockquote dir="ltr">
<p>if(myString.Substring(First,1) == myString.Substring(Second,1))</p>
<p>{</p>
<blockquote dir="ltr">
<p>First &#43;&#43;;</p>
<p>Second --;</p>
</blockquote>
<p>}else{</p>
<blockquote dir="ltr">
<p>return false;</p>
</blockquote>
<p>}</p>
</blockquote>
<p>}</p>
<p>return true;</p>
</blockquote>
<p>}</p>
<p>posted by CRPietschmann</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289766420000000</link>
		<pubDate>Tue, 24 Aug 2004 20:37:22 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289766420000000</guid>
		<dc:creator>CRPietschmann</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[I'd do a different algorithm to allow for more flexibility (to allow for different collations, for example)<br>
1) Find or write a string_reverse() function that would take a string and return it's reverse (for example, string_reverse(&quot;ABCDE&quot;) would be &quot;EDCBA&quot;) - this would have to handle Unicode data intelligently as the byte-reverse order of a set of bytes is not the
 same as the character-reverse order of a Unicode string.&nbsp; UTF-8 is also different from UTF-16 or UTF-32.&nbsp; If the data is guaranteed US-ASCII this is not a problem.<br>
2) write is_palindrome(s) as follows:<br>
<br>
Count the number of characters (not bytes) in the string using a string_length function<br>
Create four local string variables s1, s2, s3, and s4<br>
<br>
s1 &lt;= Make a copy of s<br>
Strip all palindrome-insignificant characters from s1 (punctuation, whitespace, etc.)&nbsp; Perhaps it would be easier to define palindrome-significant characters (A-Z, sure.&nbsp; 0-9? _? &quot;-&quot;?&nbsp; Are accented characters to be replaced with their vanilla equivalents?&nbsp;
 Perhaps preserve accented characters and let string_compare handle that.)<br>
Canonicalize case of s1 as appropriate - all upper-case or lower-case<br>
<br>
If the number of characters in the string is odd:<br>
&nbsp;&nbsp;&nbsp; * Set s1 = the first half of the string, NOT including the middle character<br>
&nbsp;&nbsp;&nbsp; * Set s2 = the second half of the string, also NOT including the middle character.<br>
&nbsp;&nbsp;&nbsp; * Note if s was a single character (smallest positive odd number), both s1 and s2 are the empty string.<br>
Otherwise I can safely assume the number of characters in the string is even (perhaps 0)<br>
&nbsp;&nbsp;&nbsp; * Set s1 = the first half of the string<br>
&nbsp;&nbsp;&nbsp; * Set s2 = the second half of the string<br>
<br>
Here the branches join again.<br>
<br>
Set s3 = string_reverse(s2)<br>
if s2 and s3 are &quot;the same&quot; (with respect to collation) then return TRUE<br>
otherwise return FALSE<br>
&nbsp;&nbsp;&nbsp; * Create a copy s3 = string_reverse(s2)<br>
&nbsp;&nbsp;&nbsp; * if s2 and s3 are &quot;the same&quot; (with respect to collation) then return TRUE<br>
&nbsp;&nbsp;&nbsp; * otherwise return FALSE<br>
<br>
There it is<br>
<br>
It would take a lot more code than I feel comfortable typing right now.<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289796590000000</link>
		<pubDate>Tue, 24 Aug 2004 21:27:39 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289796590000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>The message that I am getting from this fictional interview question is, “Please solve this ridiculous problem to prove to me that you are intelligent.”</p>
<p>This line of command and performance encourages pride in being able to solve the specific problem without placing the problem in context. It sends out a false sense of security in being able to do whatever it takes to get the job done. It encourages “hard
 coding” instead of developing <i>once</i> for many problems.</p>
<p>And <i>talking</i> about this matter instead of <i>writing</i> code in this post is just me showing many sophomoric folk out there in the “real” world that I am simply stalling because I cannot solve the problem. I am using my slick talk to slide out of
 getting “real” work done. Right?</p>
<p>Many, many years ago, I failed to answer a job interview question where the interviewer was measuring my experience with VBA by finding out if I knew whether the StrReverse() function existed or not. What the interviewer would never know is that I wrote
 all of my string handling functions years before the interview and years before the StrReverse() function appeared in VBA. So I was doomed because I was unaware of this new function and I failed to memorize my own code that worked so well I forgot about it!</p>
<p>I will have the same problem now with C# because I fully intend to write my code so well that I won’t need to memorize every algorithm just to impress an interviewer. In the same manner that writing in Microsoft Word 2003 does not improve spelling skills,
 writing good code does not help me remember every algorithm under the sun. “Good” code is meant to be forgotten—and “good” documentation helps us remember in the appropriate context.</p>
<p>To me, the best way to interview a programmer is to put her in a room with a computer, tell her what the problem is and walk out of the room with a promise to return in 15 minutes. Very, very few programmers get the opportunity to stand up in front of a
 white board and “lecture” to people about solving the problem.</p>
<p>posted by rasx</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289797370000000</link>
		<pubDate>Tue, 24 Aug 2004 21:28:57 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289797370000000</guid>
		<dc:creator>rasx</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[oopsie - s1 used for two different purposes.&nbsp; Rename the first occurrence s0.<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289797750000000</link>
		<pubDate>Tue, 24 Aug 2004 21:29:35 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289797750000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Hmmm... there's also the question of memory.&nbsp; If there's a large chunk of lower-case punctuation-free white-space US-ASCII data, the video algorithm is much better.&nbsp; Consider a lower-case punctuation-free white-space copy of War and Peace.<br>
<br>
Any string_reverse() algorithm is going to make a copy of either the whole string or half the string (depending on whether it's split in the middle first.)&nbsp; This could be a problem if it's a very large string.<br>
<br>
So maybe the best thing to do is check<br>
(i) whether it's pure ASCII<br>
(ii) whether it's very big<br>
and let these choices decide the algorithm.<br>
<br>
If it's a very big string, there's also the idea of checking (say) 50 random places in the first half of the string against their corresponding mirror locations.&nbsp; If any one of them fails, you can stop right there and don't have to do a string copy.&nbsp; Big win.&nbsp;
 If you do have to do a string copy, the time you spent on the 50 random places is miniscule in comparison to all the memory swapping you're going to have to do to get a copy (or half a copy.)<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289802610000000</link>
		<pubDate>Tue, 24 Aug 2004 21:37:41 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289802610000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Just so the VB.NET folks don't feel too left out...<br>
<br>
<p>Private Function IsPalindrome(ByVal TestString As String) As Boolean</p>
<p>Dim First As Integer = 0</p>
<p>Dim Last As Integer = TestString.Length - 1</p>
<p>While First &lt; Last</p>
<p>&nbsp;&nbsp;&nbsp;If TestString.Substring(First, 1) =&nbsp;TestString.Substring(Last, 1) Then</p>
<p>First &#43;= 1</p>
<p>Last -= 1</p>
<p>Else</p>
<p>Return False</p>
<p>End If</p>
<p>End While</p>
<p>Return True</p>
<p>End Function</p>
<p>posted by Gerard O&#39;Donnell</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289803640000000</link>
		<pubDate>Tue, 24 Aug 2004 21:39:24 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289803640000000</guid>
		<dc:creator>Gerard O&#39;Donnell</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Here's a good test string:<br>
A man, a plan, a canal - Panamá!<br>
(Just in case, the second-to-the-last character is an a with a right-leaning accent.)<br>
This is a good check for<br>
(1) case-insensitivity<br>
(2) accent-matching<br>
(3) the two combined (capital A vs. small a-with-accent)<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289808710000000</link>
		<pubDate>Tue, 24 Aug 2004 21:47:51 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289808710000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[It's tempting to do the whole thing in SQL.&nbsp; Then the collation stuff is automatic.<br>
<br>
Too bad REVERSE() doesn't take ntext or it would be real easy.<br>
<br>
pseudo-SQL follows<br>
<br>
PROCEDURE<br>
&nbsp;&nbsp;&nbsp; IsPalindrome<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; @string ntext (in)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; @ispalindrome bit (out)<br>
AS<br>
BEGIN<br>
declare @a nchar<br>
declare @b nchar<br>
declare @done bit<br>
declare @interestingcharacterpat = '[a-zA-Z]'<br>
declare @length numeric<br>
declare @index1 numeric<br>
declare @index2 numeric<br>
<br>
select<br>
&nbsp;&nbsp;&nbsp; @done = 0,<br>
&nbsp;&nbsp;&nbsp; @index1 = 1,<br>
&nbsp;&nbsp;&nbsp; @length = len(@string), -- use len, not datalength - characters, not bytes<br>
&nbsp;&nbsp;&nbsp; @index2 = @length<br>
<br>
while @index1 &lt;= @index2<br>
begin<br>
&nbsp;&nbsp;&nbsp; -- get the first interesting character<br>
&nbsp;&nbsp;&nbsp; select<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @a = substring(@string, @index1, 1) -- uses characters<br>
&nbsp;&nbsp;&nbsp; while (@a NOT LIKE @interestingcharacterpat AND @index1 &lt;= @index2)<br>
&nbsp;&nbsp;&nbsp; begin<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; select<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @index1 = @index1 &#43; 1,<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @a = substring(@string, @index1, 1)<br>
&nbsp;&nbsp;&nbsp; end<br>
<br>
&nbsp;&nbsp;&nbsp; -- get the last interesting character<br>
&nbsp;&nbsp;&nbsp; select<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @b = substring(@string, @index2, 1) -- uses characters<br>
&nbsp;&nbsp;&nbsp; while (@b NOT LIKE @interestingcharacterpat AND @index1 &lt;= @index2)<br>
&nbsp;&nbsp;&nbsp; begin<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; select<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @index2 = @index2 - 1,<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @b = substring(@string, @index2, 1)<br>
&nbsp;&nbsp;&nbsp; end<br>
<br>
&nbsp;&nbsp;&nbsp; if @a not like @b -- use like, not == (for collation)<br>
&nbsp;&nbsp;&nbsp; begin<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; select<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @ispalindrome = 0<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return (0) -- no need to continue<br>
&nbsp;&nbsp;&nbsp; end<br>
<br>
&nbsp;&nbsp;&nbsp; -- narrow the search by one both ways<br>
&nbsp;&nbsp;&nbsp; select<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @index1 = @index1 &#43; 1,<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @index2 = @index2 - 1<br>
end<br>
<br>
select<br>
&nbsp;&nbsp;&nbsp; @ispalindrome = 1<br>
<br>
RETURN 0<br>
END<br>
<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289826690000000</link>
		<pubDate>Tue, 24 Aug 2004 22:17:49 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289826690000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Actually my code has some problems<br>
* wildcarded data in the string being misterpreted by LIKE - fix by using @a = @b (works with collation despite my previous comment)<br>
* strings like '&lt;-' with two different non-interesting-characters are falsely returned as &quot;not palindromes&quot; even though they are - create an @c for the &quot;interesting&quot; loops and only assign it to @a or @b if it ends up being interesting<br>
<br>
But I think the idea is sound<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289832940000000</link>
		<pubDate>Tue, 24 Aug 2004 22:28:14 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289832940000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Oh, and if @string is NULL there's problems - but then at the beginning something like<br>
<br>
if @string IS NULL<br>
begin<br>
&nbsp;&nbsp;&nbsp; SELECT @IsPalindrome = NULL -- pass the null through, let the caller decide<br>
&nbsp;&nbsp;&nbsp; RETURN (0)<br>
end<br>
<br>
would take care of that.<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289840300000000</link>
		<pubDate>Tue, 24 Aug 2004 22:40:30 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289840300000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>public bool IsPalindrome(string palindrome)<br>
{<br>
&nbsp;&nbsp; if(palindrome == null || palindrome.Length == 0)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br>
<br>
&nbsp;&nbsp; palindrome = palindrome.Replace(&quot; &quot;, &quot;&quot;).ToLower();<br>
&nbsp;&nbsp; int start = 0, end = palindrome.Length - 1;<br>
<br>
&nbsp;&nbsp; while(end - start &gt;= 1)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(palindrome[start] == palindrome[end])<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start&#43;&#43;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end--;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br>
&nbsp;&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp; return true;<br>
}<br>
<br>
This will validate palindromes without case sensitivity even if they have spaces, for example:&nbsp;A man a plan a canal Panama</p>
<p>posted by TimP</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289873750000000</link>
		<pubDate>Tue, 24 Aug 2004 23:36:15 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289873750000000</guid>
		<dc:creator>TimP</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p></p>
<p>public bool IsPalindrome(string palindrome)<br>
{<br>
&nbsp;&nbsp; if(palindrome == null || palindrome.Length == 0)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br>
&nbsp;&nbsp; palindrome = palindrome.Replace(&quot; &quot;, &quot;&quot;).ToLower();<br>
&nbsp;&nbsp; char[] reverse = palindrome.ToCharArray();<br>
&nbsp;&nbsp; Array.Reverse(reverse);<br>
&nbsp;&nbsp; string s = new string(reverse);<br>
&nbsp;&nbsp; return palindrome == s;<br>
}<br>
<br>
Here's a case/space insensitive and&nbsp;smaller palindrome checker.</p>
<p>posted by TimP</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289880510000000</link>
		<pubDate>Tue, 24 Aug 2004 23:47:31 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289880510000000</guid>
		<dc:creator>TimP</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Out of my own curiosity, I did a few tests to test performance. I'm no performance test guru, but what I did was use an array of 271 palindromes and an array of 271 non-palidromes, then tested the array for x Iterations. The score on top is using&nbsp;the Array.Reverse
 method&nbsp;(the method I posted second) and the&nbsp;bottom score&nbsp;checking character by character (the method I posted first). The score is the average number of ticks per method call. The average non-palindrome was longer than the average palindrome, so that may account
 for the slightly slower performance.<br>
<br>
Palindromes:</p>
<p>1000 Iterations<br>
18.1072177121771<br>
1000 Iterations<br>
12.1946568265683<br>
<br>
5000 Iterations<br>
17.8115896678967<br>
5000 Iterations<br>
12.046842804428<br>
<br>
10000 Iterations<br>
17.2203335793358<br>
10000 Iterations<br>
11.4925402214022<br>
<br>
15000 Iterations<br>
17.121790897909<br>
15000 Iterations<br>
11.6280364083641<br>
<br>
20000 Iterations<br>
17.1833800738007<br>
20000 Iterations<br>
11.5294937269373<br>
<br>
30000 Iterations<br>
17.2080157441574<br>
30000 Iterations<br>
11.7019434194342<br>
<br>
Non-Palindromes:</p>
<p>1000 Iterations<br>
21.8025682656827<br>
1000 Iterations<br>
15.1509372693727<br>
<br>
5000 Iterations<br>
21.6547542435424<br>
5000 Iterations<br>
15.2248442804428<br>
<br>
10000 Iterations<br>
21.8764752767528<br>
10000 Iterations<br>
14.6335881918819<br>
<br>
15000 Iterations<br>
21.777932595326<br>
15000 Iterations<br>
14.6089525215252<br>
<br>
20000 Iterations<br>
22.0981963099631<br>
20000 Iterations<br>
14.6890184501845<br>
<br>
30000 Iterations<br>
22.3075995079951<br>
30000 Iterations<br>
14.7444487084871<br>
<br>
The character by character method beating the Array.Reverse method on non-palindromes is a no brainer, because it returns false after the first check, where as the Array.Reverse has to reverse and test the whole string every time.<br>
<br>
I was a bit surprised by it winning on palindromes, though. If anyone has any insight into this, I'd love to hear it. All I can assume is that a character by character check is more efficient than putting a string into an array, reversing it, and putting it
 back into a string.</p>
<p>posted by TimP</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289911090000000</link>
		<pubDate>Wed, 25 Aug 2004 00:38:29 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289911090000000</guid>
		<dc:creator>TimP</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>bool IsPalindrome(char *text)<br>
{<br>
&nbsp;&nbsp; if (text)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char *first = text;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char *last = text &#43; strlen(text) - 1;</p>
<p>&nbsp;&nbsp; &nbsp;&nbsp; while (first &lt;= last)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (*first != *last)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first&#43;&#43;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last--;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true;<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; return false;<br>
}</p>
<p>posted by GNUHippie</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289914180000000</link>
		<pubDate>Wed, 25 Aug 2004 00:43:38 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289914180000000</guid>
		<dc:creator>GNUHippie</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Here is&nbsp;the&nbsp;function that checks for palindrome<br>
<br>
public bool IsPalindrome(string s)<br>
&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;//Parameter validations<br>
&nbsp;&nbsp;&nbsp;if(s==null||s==string.Empty) return false ;<br>
&nbsp;&nbsp;&nbsp;//replace whitespaces<br>
&nbsp;&nbsp;&nbsp;s = s.Replace(&quot; &quot;, &quot;&quot;).ToLower();<br>
&nbsp;&nbsp;&nbsp;int len = s.Length ;<br>
&nbsp;&nbsp;&nbsp;Stack ds = new Stack(len);&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;for(int i=0;i&lt;len;i&#43;&#43;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;ds.Push(s[i]);<br>
&nbsp;&nbsp;&nbsp;for(int i=0;i&lt;len;i&#43;&#43;)<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;char c = (char)ds.Pop();<br>
&nbsp;&nbsp;&nbsp;&nbsp;if(c == s[i])<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<br>
&nbsp;&nbsp;&nbsp;&nbsp;else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;return true ;<br>
&nbsp;&nbsp;}<p>posted by rpg</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289945580000000</link>
		<pubDate>Wed, 25 Aug 2004 01:35:58 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289945580000000</guid>
		<dc:creator>rpg</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>here is my stab at the palindrome problem. its the complete code to the program and all =D and it even works with spaces <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /><br>
<br>
<br>
</p>
<p>#include &lt;iostream&gt;</p>
<p>#include &lt;algorithm&gt;</p>
<p>#include &lt;string&gt;</p>
<p>using namespace std;</p>
<p>bool IsPalindrome(string strName)</p>
<p>{</p>
<p>string strReverse = strName;</p>
<p>if(strName == &quot;&quot;)</p>
<p>{ </p>
<p>return false;</p>
<p>}</p>
<p>reverse(strReverse.begin(), strReverse.end());</p>
<p>for(int i = 0; i &lt; strName.size(); i&#43;&#43;)</p>
<p>{</p>
<p>if( strName[i] == strReverse[i] )</p>
<p>{</p>
<p>continue;</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>return false;</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>int main()</p>
<p>{</p>
<p>string strPalindrome;</p>
<p>cout &lt;&lt; &quot;Enter a word: &quot;;</p>
<p>getline(cin, strPalindrome);</p>
<p></p>
<p>if(IsPalindrome(strPalindrome.c_str()) == false )</p>
<p>{</p>
<p>cout &lt;&lt; strPalindrome &lt;&lt; &quot; is not a palindrome&quot; &lt;&lt; endl;</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>cout &lt;&lt; strPalindrome &lt;&lt; &quot; is a palindrome&quot; &lt;&lt; endl;</p>
<p>}</p>
<p></p>
<p>getchar();</p>
<p>getchar();</p>
<p>return 0;</p>
<p>}</p>
<p>posted by goodeffort</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289968040000000</link>
		<pubDate>Wed, 25 Aug 2004 02:13:24 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289968040000000</guid>
		<dc:creator>goodeffort</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[So, in the Longhorn timeframe, we'd just call <br>
<br>
bool b = System.String.IsPalindrome(str, <br>
&nbsp;&nbsp; PalindromeOptions.CaseInsensative);<br>
<br>
, right?<p>posted by cwilliams1145</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289980080000000</link>
		<pubDate>Wed, 25 Aug 2004 02:33:28 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632289980080000000</guid>
		<dc:creator>cwilliams1145</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>// This function will check if there is any alpha-numeric characters and if they orginise a palindrome<br>
// Examples: <br>
//&nbsp; &quot;ABBA&quot;&nbsp; = true<br>
// &quot;Borrow or rob?&quot;&nbsp; = true<br>
// &quot;ABCD&quot; = false<br>
// &quot;?!?&quot;&nbsp;&nbsp; = false<br>
bool IsPalindrome(TCHAR* str) {</p>
<p>&nbsp;// Special case , invalid input can not be palindrome<br>
&nbsp;if (NULL==str) {<br>
&nbsp;&nbsp; return false;<br>
&nbsp;}</p>
<p>&nbsp;// Pointer to first character in string<br>
&nbsp;TCHAR* first = str; // Initialy point to start of string<br>
&nbsp;// Pointer to second character in string<br>
&nbsp;TCHAR* second = first;&nbsp;<br>
&nbsp;// Pointer to last character in string<br>
&nbsp;TCHAR* last&nbsp; = str &#43; _tsclen(str); // Initialy point to null terminator<br>
// Point to terminator character (not nessesary NULL terminator!)<br>
&nbsp;TCHAR* term = last; <br>
&nbsp;// Flag to indicate if any alpha-numeric characters were found<br>
&nbsp;bool&nbsp;&nbsp; nonEmpty = false;</p>
<p>&nbsp;do {<br>
&nbsp;&nbsp; do {<br>
&nbsp;&nbsp;&nbsp; // Threat second character as start of new string <br>
&nbsp;&nbsp;&nbsp; first = second;</p>
<p>&nbsp;&nbsp;&nbsp; // Get pointer to next character in new string<br>
&nbsp;&nbsp;&nbsp; // Will be used to calculate length of first character<br>
&nbsp;&nbsp;&nbsp; second = CharNext(first);</p>
<p>&nbsp;&nbsp;&nbsp; // If first character point to terminator - this mean that there is no any valid
<br>
&nbsp;&nbsp;&nbsp; // characters - so nothing that can be different. Stop comparation<br>
&nbsp;&nbsp;&nbsp; if (first&gt;=term) return nonEmpty;<br>
&nbsp;&nbsp; } while (!IsCharAlphaNumeric(*first));</p>
<p>&nbsp;&nbsp; do {<br>
&nbsp;&nbsp;&nbsp;&nbsp; // Thread previous character as terminator of new string<br>
&nbsp;&nbsp;&nbsp;&nbsp; term = last;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; // Extract character previous to new terminator<br>
&nbsp;&nbsp;&nbsp;&nbsp; last = CharPrev(str,term);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; // If we terminator crossed start of our string - return information we know already<br>
&nbsp;&nbsp;&nbsp;&nbsp; if (first&gt;=term) return nonEmpty;<br>
&nbsp;&nbsp; } while(!IsCharAlphaNumeric(*last));</p>
<p>&nbsp;&nbsp; // Compare thouse extracted characters if they are equal<br>
&nbsp;&nbsp; if (CompareString(LOCALE_SYSTEM_DEFAULT, // Use system default because IsCharAlphaNumeric rely on system default<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NORM_IGNORECASE | NORM_IGNOREWIDTH | NORM_IGNOREKANATYPE, // Some crazy flags <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first,&nbsp; // first alphanumeric chacter in our string<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; second-first, // length of first character<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last, // last alphanumeric character<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; term-last&nbsp;&nbsp;&nbsp; // length of last character<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) != CSTR_EQUAL) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false; <br>
&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp; // Here we can set flag to indicate if any AlphaNumeric characters were found
<br>
&nbsp;&nbsp; nonEmpty = true;</p>
<p>&nbsp;// Loop while there any character beetwean start of string and previnator<br>
&nbsp;} while (first&lt;term);<br>
&nbsp;<br>
&nbsp;// Looks like nothing wrong were found<br>
&nbsp;// This is valid palindrome<br>
&nbsp;// But it will be nice to check if any AlphaNumeric were found<br>
&nbsp;return nonEmpty;<br>
}</p>
<p>P.S&gt; This is C&#43;&#43; source code. To convert to C declare variables early. I'm unsure it will compile and work - I've coded it in WordPad <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /><br>
&nbsp;<br>
<strong>NOTE: </strong>As I've <a href="http://msdn.microsoft.com/library/en-us/intl/unicode_192r.asp">
found</a>&nbsp;CharPrev and CharNext does not support Unicode 2.0 surrogates. Also this is unknown if CompareString support them.
<br>
But this is definitely an issue with IsCharAlphaNumeric function.<br>
Looks like modification requered to work with Unicode correctly <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-6.gif' alt='Sad' /></p>
<p>posted by AT</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290005350000000</link>
		<pubDate>Wed, 25 Aug 2004 03:15:35 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290005350000000</guid>
		<dc:creator>AT</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>There's lots of code already here, so I won't add mine, but there are some issues&nbsp;such as desired behavior (and security) that should be addressed prior to coding, and I'm rather surprised they haven't been addressed yet in this thread.<br>
<br>
How is the algorithm to handle punctuation and whitespace?&nbsp; My thoughts are to strip them off prior to the forward/reverse iterative checking loop.<br>
<br>
When dealing with TCHAR's the issue of internationalization needs addressed; this introduces some other interesting concepts.<br>
<br>
Should case be considered?&nbsp; Some languages have single character lower case but that same &quot;character&quot; in upper case is actually two characters (ala the German ß (sharp-s).&nbsp; This makes for interesting buffer manipulation.<br>
<br>
Should accented characters be accepted as equivalent to non-accented characters?&nbsp; In Turkish, there are four&nbsp;representations of the letter 'i' that are all&nbsp;equivalent&nbsp;if you are ignoring case.&nbsp;
<br>
<br>
Should we even consider the culture of the source string, or assume the current culture?<br>
<br>
Last, but not least, is the issue of string length.&nbsp; These days, I am surprised that the interviewer/interviewee did not add a string length parameter, stipulate the string is null-terminated, or better yet #include&nbsp;strsafe.h above the function prototype.<br>
<br>
I'm also wondering if asking for these types of clarifications is too much - the interviewer may be thinking &quot;get on with it already, I just want to know if you understand pointer arithmetic!&quot;</p>
<p>posted by boneman</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290050320000000</link>
		<pubDate>Wed, 25 Aug 2004 04:30:32 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290050320000000</guid>
		<dc:creator>boneman</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[For my own edification primarily, could you do this with regex?<br>
<br>
ignore case, iternational, etc<br>
<br>
strip white space, symbols, numerals etc<br>
get length of string<br>
divide by two = base length<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if not divisible by two -&quot;not palindrome&quot;<br>
<br>
net length = base length - 2 // you do not have to compare the last two letters if all&nbsp;others match.<br>
<br>
compare&nbsp;first and last character <br>
&nbsp;&nbsp;&nbsp; if no match - &quot;not palindrome&quot;&nbsp;<br>
compare second and second&nbsp;last........<br>
<br>
this is bloody rough, hope you get the gist&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<p>posted by bishfish</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290081330000000</link>
		<pubDate>Wed, 25 Aug 2004 05:22:13 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290081330000000</guid>
		<dc:creator>bishfish</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Hi everyone!&nbsp; Evan Goldring here (the one who got talked into making my whiteboard coding public!).<br>
<br>
Having read through many of the posts in reply to the video, I want to say that I see a lot of great thinking around this particular coding question.&nbsp; Many of you are thinking clearly through the whole problem, which is very important.&nbsp; It really underscores
 the &quot;think first, then code&quot; mentality I talked about in the video.<br>
<br>
What I'm even more impressed with is seeing some of you going above and beyond and starting to think about the next logical question that an interviewer might ask: How would you test this code.&nbsp; Thoughts on security, performance, and other issues raised are
 great to see.&nbsp; It's not all about the code functioning correctly.&nbsp; As I mentioned in the video, I'm an
<a href="http://weblogs.asp.net/jobsblog/archive/2004/05/27/143419.aspx">SDE/T</a> manager, so the follow-up test question is one I use often.&nbsp;
<br>
<br>
Although mentioned almost everywhere you are reading about technical interviewing, I feel it is worth repeating here: As an interviewer, I'm not necessarily looking just at what your answer was, but HOW you answered the question.&nbsp; Although contrary to popular
 belief, questions like this aren't a &quot;final exam&quot;&nbsp;with a strict Pass/Fail grade based solely on the code you wrote judged against some mythical &quot;right&quot; answer.&nbsp; There are many &quot;right&quot; answers with even more unique paths to get there.&nbsp; These questions are a
 good look beyond just &quot;coding&quot; into your engineering style, problem solving approach/skills, how you handle a new challenge, how you deal with being put on the spot - the list goes on.&nbsp;
<br>
<br>
Finally,&nbsp;remember that this is only one of many types of questions you'll see in a technical interview (at Microsoft or otherwise).&nbsp; For a good summary of what to expect in general, take a look at these two posts at the Technical Careers at Microsoft blog:
<a href="http://weblogs.asp.net/jobsblog/archive/2004/05/12/130594.aspx">Part I</a> and
<a href="http://weblogs.asp.net/jobsblog/archive/2004/05/13/131278.aspx">Part II</a> of Interviewing at Microsoft.</p>
<p>posted by Icon</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290091220000000</link>
		<pubDate>Wed, 25 Aug 2004 05:38:42 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290091220000000</guid>
		<dc:creator>Icon</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>//This does not handle white space but it should efficiently</p>
<p>//look for a forward and reverse character pattern. like so &quot;ab c ba&quot;</p>
<p>bool IsPalendrone(char* ptext)</p>
<p>{</p>
<blockquote dir="ltr">
<p>bool rtnval = true;</p>
<p></p>
<p>//Check for NULL or a zero length string</p>
<p>if((ptext == NULL) || (*ptext == 0))</p>
<blockquote dir="ltr">
<p>return false;</p>
</blockquote>
<p>int textlen = strlen(ptext);</p>
<p></p>
<p>//Check for the case where ptext is only on char</p>
<p>if(textlen == 1)</p>
<blockquote dir="ltr">
<p>return rtnval;</p>
</blockquote>
<p>//ptext is more than one car we need to do some</p>
<p>//comparisons</p>
<p>char* lptr = ptext;</p>
<p>char* rptr = ptext &#43; (textlen - 1);</p>
<p>do</p>
<p>{</p>
<blockquote dir="ltr">
<p>//If we find a case where the character pointed to on</p>
<p>//the left and right are not equal we can say this is</p>
<p>//not a palendrone</p>
<p>if((*lptr) != (*rptr))</p>
<p>{</p>
<blockquote dir="ltr">
<p>rtnval = false;</p>
<p>break;</p>
</blockquote>
<p>}</p>
<p>//Move our pointer towards each other</p>
<p>lptr&#43;&#43;;</p>
<p>rptr--;</p>
</blockquote>
<p>}while(lptr &lt;= rptr);</p>
<p>return rtnval;</p>
</blockquote>
<p>}</p>
<p>posted by myronww</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290098730000000</link>
		<pubDate>Wed, 25 Aug 2004 05:51:13 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290098730000000</guid>
		<dc:creator>myronww</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Actually I think I could get away with performing one less iteration for odd length strings by changing<br>
<br>
while(lptr &lt;= rptr);<br>
<br>
to<br>
<br>
while(lptr &lt; rptr);<br>
<br>
because we would not need to look at the center character for odd length strings.<p>posted by myronww</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290102990000000</link>
		<pubDate>Wed, 25 Aug 2004 05:58:19 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290102990000000</guid>
		<dc:creator>myronww</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[rasx writes:<br>
&quot;To me, the best way to interview a programmer is to put her in a room with a computer, tell her what the problem is and walk out of the room with a promise to return in 15 minutes. Very, very few programmers get the opportunity to stand up in front of a white
 board and “lecture” to people about solving the problem&quot;<br>
<br>
This only works if the person is not expected to work on a team.&nbsp; If they are just expected to sit and hack out their code then fine.&nbsp; Software that is large and complicated requires a team of people with good communication skills.&nbsp; That is the real goal of
 the white board test.&nbsp; <br>
<p>posted by barlo_mung</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290155530000000</link>
		<pubDate>Wed, 25 Aug 2004 07:25:53 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290155530000000</guid>
		<dc:creator>barlo_mung</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[i would just like to&nbsp;point out&nbsp;that mine handles spaces, every type of character, numbers and letters, and &nbsp;the whole schmeal. EXCEPT, now that you mention it i never checked about casing. now i ask this question though, is aBbA&nbsp;or AbBa a palindrome. basically
 i want someone to list the criteria that makes a string a palindrome and we can work from there.<p>posted by goodeffort</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290181440000000</link>
		<pubDate>Wed, 25 Aug 2004 08:09:04 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290181440000000</guid>
		<dc:creator>goodeffort</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[<b>
<p></b>static<b> </b>private<b> </b>bool<b> isPalindrome (</b>string<b> stringToTest)</p>
<p>{</p>
<p></b>char<b>[] stringChars = stringToTest.ToCharArray();</p>
<p></p>
<p></b>foreach<b> (</b>char<b> character </b>in<b> stringChars)</p>
<p>{</p>
<p></b>if<b> (</b>char.IsPunctuation(character) || char.IsSeparator(character))</p>
<b>
<p>{</p>
<p>stringToTest = stringToTest.Replace(character.ToString(), </b>&quot;&quot;<b>).ToLower();</p>
<p>}</p>
<p>}</p>
</b><b>
<p></b>if<b> (stringToTest.Length % 2 == 0) </b>// even number of characters in the string</p>
<b>
<p>{</p>
<p></b>int<b> halfwayMark = (stringToTest.Length/2);</p>
<p></b>char<b>[] firstHalf = stringToTest.Substring(0, halfwayMark).ToCharArray();</p>
<p></b>char<b>[] secondHalf = stringToTest.Substring(halfwayMark, stringToTest.Length-halfwayMark).ToCharArray();</p>
</b><b>
<p></b>bool<b> flag = </b>true<b>; </b>// innocent until proven guilty</p>
<b>
<p>Array.Reverse(secondHalf);</p>
</b><b>
<p></b>for<b> (</b>int<b> i=0;i&lt;halfwayMark;i&#43;&#43;)</p>
<p>{</p>
<p></b>if<b> (firstHalf[i] != secondHalf[i])</p>
<p>{</p>
<p>flag = </b>false<b>;</p>
<p></b>break<b>; </b>// break out of the loop</p>
<b>
<p>}</p>
<p>}</p>
<p></b>return<b> flag;</p>
<p>}</p>
<p></b>else<b> </b>// odd number of chars, middle char needs to be ignored</p>
<b>
<p>{</p>
<p></b>int<b> halfwayMark = (stringToTest.Length/2) &#43; 1;</p>
<p></b>char<b>[] firstHalf = stringToTest.Substring(0, halfwayMark).ToCharArray();</p>
<p></b>char<b>[] secondHalf = stringToTest.Substring(--halfwayMark).ToCharArray();</p>
</b><b>
<p></b>bool<b> flag = </b>true<b>;</p>
</b><b>
<p>Array.Reverse(secondHalf);</p>
</b><b>
<p></b>for<b> (</b>int<b> i=0;i&lt;halfwayMark;i&#43;&#43;)</p>
<p>{</p>
<p></b>if<b> (firstHalf[i] != secondHalf[i])</p>
<p>{</p>
<p>flag = </b>false<b>;</p>
<p></b>break<b>; </b>// break out of the loop</p>
<b>
<p>}</p>
<p>}</p>
<p></b>return<b> flag;</p>
<p>}</p>
<p>}</p>
</b><p>posted by x.static</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290193940000000</link>
		<pubDate>Wed, 25 Aug 2004 08:29:54 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290193940000000</guid>
		<dc:creator>x.static</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[I think I'd prefer something simple like <br>
<pre>bool IsPalindrome1(string &amp;s)<br>{<br>	if(s.length() == 0) return false;<br>	string::iterator begin = s.begin();<br>	string::iterator last = s.end() -1;<br>	while(begin &lt; last)<br>	{<br>		if(*begin&#43;&#43; != *last--) return false;<br>	}<br>	return true;<br>}<br><br></pre>
and go on from there. always liked iterators. <br>
<p>posted by mwirth</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290244900000000</link>
		<pubDate>Wed, 25 Aug 2004 09:54:50 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290244900000000</guid>
		<dc:creator>mwirth</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[What happened to good old recursiveness? <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /><br>
<br>
This version should work for sentences as well (with punctuations etc).<br>
<br>
<p>public bool IsPalindrome(string inputString)<br>
{<br>
&nbsp;StringBuilder inputStringBuilder = new StringBuilder(inputString);<br>
&nbsp;for (int i = inputString.Length-1; i &gt; -1; i--)<br>
&nbsp; {<br>
&nbsp;&nbsp; if (!Char.IsLetterOrDigit(inputString.Substring(i, 1),0))<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; inputStringBuilder.Remove(i, 1);<br>
&nbsp;&nbsp; }<br>
&nbsp; }<br>
&nbsp;return IsPalindromeNormalized( inputStringBuilder.ToString().ToLower());<br>
}<br>
<br>
private bool IsPalindromeNormalized(string inputString)<br>
{<br>
&nbsp;switch (inputString.Length)<br>
&nbsp;{<br>
&nbsp; case 0:<br>
&nbsp;&nbsp; return false;<br>
&nbsp;&nbsp; break;<br>
&nbsp; case 1:<br>
&nbsp;&nbsp; return true;<br>
&nbsp;&nbsp; break;<br>
&nbsp; case 2:<br>
&nbsp;&nbsp; return inputString.Substring(0, 1) == inputString.Substring(1, 1);<br>
&nbsp;&nbsp; break;<br>
&nbsp; default:<br>
&nbsp;&nbsp; if (inputString.Substring(0, 1) == inputString.Substring(inputString.Length - 1, 1))<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; return IsPalindromeNormalized(inputString.Substring(1, inputString.Length - 2));<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; else<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp; &nbsp;return false;<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; break;<br>
&nbsp;}<br>
}</p>
<p>posted by PeterF</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290249890000000</link>
		<pubDate>Wed, 25 Aug 2004 10:03:09 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290249890000000</guid>
		<dc:creator>PeterF</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Sorry, somehow felt compelling to be original <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /><br>
<br>
Well, reversing the string is off course a very simple and wise choice not to over-complicate the code and move on to the next task. If speed&nbsp;would be a goal&nbsp;(when using it very often), it would depend on the type of input data. If you would check the English
 dictionary for Palindromes, the reversing strings step&nbsp;could in the end be a more time consuming task than moving pointers, compare and return false after the first few&nbsp;iterations in most cases...<br>
<p>posted by PeterF</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290305920000000</link>
		<pubDate>Wed, 25 Aug 2004 11:36:32 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290305920000000</guid>
		<dc:creator>PeterF</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Why recurse when someone else has already written the code for you?<br>
<br>
&nbsp;&nbsp;&nbsp; Private Function IsPalindrome(ByVal strTest As String) As Boolean</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (strTest.Length &gt; 0) Then</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim sourceArray As Char() = strTest.ToCharArray()</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim reversedArray(sourceArray.Length - 1) As Char</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Array.Copy(sourceArray, reversedArray, sourceArray.Length)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reversedArray.Reverse(reversedArray)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return (sourceArray = reveredArray)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return (False)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</p>
<p>&nbsp;&nbsp;&nbsp; End Function<br>
<br>
<strong>BLOG: </strong><a href="http://www.anguslogan.com">www.anguslogan.com</a></p>
<p>posted by anguslogan</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290313050000000</link>
		<pubDate>Wed, 25 Aug 2004 11:48:25 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290313050000000</guid>
		<dc:creator>anguslogan</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>just out of curiosity i also did some timing. the first version was pretty much the version in the video: TCHAR* char by char comparison and incrementing/decrementing pointers.
<br>
the second fragment was the std::string::iterator based version (same thing here, comparing the dereferenced iterators and incrementing/decrementing).
<br>
<br>
these should be very accurate data.&nbsp;i used queryperformancecounter-based timing routines, release build with vs2003.
<br>
<br>
1000000 runs (in seconds, doesn't matter for this comparison, though): <br>
<br>
tchar-pointer-method:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.17408<br>
<br>
iterator-method:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.0713183<br>
<br>
the iterator-method seemed to be much faster. ripping out the calls to _tcslen() in the tchar-pointer-method improves the situation (note: no length needed in the iterator-based version, of course):
<br>
<br>
tchar-pointer-w/o-tcslen-method:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.0578906<br>
<br>
seems that the strlen functions are a real performance problem. I found it very interesting that the iterator version is so close to the _TCHAR* version.. i was a little surprised actually.
<br>
<br>
i know these measurements don't reveal anything new. just thought it would be interesting to compare a little... &quot;old style&quot; vs. &quot;new style&quot; <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /><br>
<br>
</p>
<p>posted by mwirth</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290329430000000</link>
		<pubDate>Wed, 25 Aug 2004 12:15:43 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290329430000000</guid>
		<dc:creator>mwirth</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Here's my javascript implementation.&nbsp; I couldn't find a way to make javascript equate accented characters of the same character class (a, a w/accent, a w/ring, etc.) so this is katana-sensitive.<br>
<br>
Comes with a driver function and a test-driving form.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
&lt;h1&gt;Javascript: function is_palindrome(s)&lt;/h1&gt;</p>
<p>&lt;script type=&quot;text/javascript&quot;&gt;</p>
<p>// driver function<br>
function check_palindrome(s)<br>
{&nbsp;var b = is_palindrome(s);</p>
<p>&nbsp;if (b)<br>
&nbsp;{&nbsp;alert(&quot;YES\n\n&quot; &#43; s &#43; &quot;\n\nIS a palindrome\n&quot;);<br>
&nbsp;} else if (b == null)<br>
&nbsp;{&nbsp;alert(&quot;Is null a palindrome?&nbsp; The answer is null.&quot;);<br>
&nbsp;} else<br>
&nbsp;{&nbsp;alert(&quot;NO\n\n&quot; &#43; s &#43; &quot;\n\nIS NOT a palindrome\n&quot;);<br>
&nbsp;}<br>
}</p>
<p>// doesn't collate (n w/tilde doesn't match n w/o tilde)<br>
// if accents are necessary then a Unicode-based function is probably the best way to go<br>
function is_palindrome(s)<br>
{&nbsp;if (s == null) return null;&nbsp; // pass ambiguity back to caller - let them decide</p>
<p>&nbsp;var interestingcharspat = /[a-z]/i; // maybe add digits? or do /[:alpha:]/<br>
&nbsp;var casesensitive = 0;<br>
&nbsp;var index_left = 0;<br>
&nbsp;var index_right = s.length - 1;<br>
&nbsp;var char_left;<br>
&nbsp;var char_right;<br>
&nbsp;var debug = 1;</p>
<p>&nbsp;while (index_left &lt; index_right)<br>
&nbsp;{<br>
&nbsp;&nbsp;if (debug) alert(s.charAt(index_left) &#43; &quot;, &quot; &#43; s.charAt(index_right) &#43; &quot; at &quot; &#43; index_left &#43; &quot;, &quot; &#43; index_right);<br>
&nbsp;&nbsp;// get first interesting character on the left<br>
&nbsp;&nbsp;while (<br>
&nbsp;&nbsp;&nbsp;index_left &lt; index_right &amp;&amp;<br>
&nbsp;&nbsp;&nbsp;!interestingcharspat.test(s.charAt(index_left))<br>
&nbsp;&nbsp;)<br>
&nbsp;&nbsp;{&nbsp;index_left&#43;&#43;;<br>
&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;if (debug) alert(s.charAt(index_left) &#43; &quot;, &quot; &#43; s.charAt(index_right) &#43; &quot; at &quot; &#43; index_left &#43; &quot;, &quot; &#43; index_right);<br>
&nbsp;&nbsp;// get first interesting character on the right<br>
&nbsp;&nbsp;while (<br>
&nbsp;&nbsp;&nbsp;index_left &lt; index_right &amp;&amp;<br>
&nbsp;&nbsp;&nbsp;!interestingcharspat.test(s.charAt(index_right))<br>
&nbsp;&nbsp;)<br>
&nbsp;&nbsp;{&nbsp;index_right--;<br>
&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;if (debug) alert(s.charAt(index_left) &#43; &quot;, &quot; &#43; s.charAt(index_right) &#43; &quot; at &quot; &#43; index_left &#43; &quot;, &quot; &#43; index_right);<br>
&nbsp;&nbsp;// if index_left &gt;= index_right we're done<br>
&nbsp;&nbsp;if (index_left &lt; index_right)<br>
&nbsp;&nbsp;{&nbsp;char_left = s.charAt(index_left);<br>
&nbsp;&nbsp;&nbsp;char_right = s.charAt(index_right);</p>
<p>&nbsp;&nbsp;&nbsp;// handle case insensitivity<br>
&nbsp;&nbsp;&nbsp;if (!casesensitive)<br>
&nbsp;&nbsp;&nbsp;{&nbsp;char_left = char_left.toUpperCase(); // no-op on nonletters<br>
&nbsp;&nbsp;&nbsp;&nbsp;char_right = char_right.toUpperCase(); // no-op on nonletters<br>
&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;// if there's a mismatch then it's NOT a palindrome<br>
&nbsp;&nbsp;&nbsp;if (char_left != char_right)<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;if (debug) alert(char_left &#43; &quot;, &quot; &#43; char_right &#43; &quot; at &quot; &#43; index_left &#43; &quot;, &quot; &#43; index_right);<br>
&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>
&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;// otherwise narrow the search by one<br>
&nbsp;&nbsp;&nbsp;index_left&#43;&#43;;<br>
&nbsp;&nbsp;&nbsp;index_right--;<br>
&nbsp;&nbsp;}<br>
&nbsp;}</p>
<p>&nbsp;// if we made it through with no mismatches it's a palindrome<br>
&nbsp;return true;<br>
}</p>
<p>&lt;/script&gt;</p>
<p>doesn't equate accented characters with their unaccented equivalent<br>
&lt;form onsubmit=&quot;check_palindrome(this.string.value); return false;&quot;&gt;<br>
&lt;textarea name=&quot;string&quot; rows=&quot;10&quot; cols=&quot;50&quot;<br>
&nbsp;&gt;A man, a plan, a canal - Panama!&lt;/textarea&gt;&lt;br&gt;<br>
&lt;input type=&quot;submit&quot; value=&quot;Check Palindrome-ness&quot;&gt;<br>
&lt;/form&gt;</p>
<p>&lt;a href=&quot;#&quot; onclick=&quot;check_palindrome(null); return false;&quot;&gt;Check palindrome-ness of null&lt;/a&gt;</p>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290358300000000</link>
		<pubDate>Wed, 25 Aug 2004 13:03:50 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290358300000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Beyond the specifics of the problem definition (what is a palindrome, case sensitivity, whitespace, punctiation, etc.) I think that it's also important to ask what properties the ideal solution should have.&nbsp; Many posters have utilized pre-built string reversals
 and string compares.&nbsp; This allows them to code a quick solution, but it may not be the most optimal in terms of performance, i.e. cpu time and memory utilization.<br>
<br>
My thought process followed something like this:<br>
<br>
1. work on the assumption that the best solution is the most efficient at execution time.&nbsp; This makes the problem more interesting...<br>
<br>
2. Reverse and compare are too expensive in terms of CPU and Memory.<br>
<br>
3.&nbsp;I think you should be able to do that at around O(n), where n is the length of the string.<br>
<br>
4.&nbsp; I played around with different ideas about traversing the string once, and creating a hash of 1) the entire string, and 2) the first half of the string.&nbsp; The importance of the order of the characters makes this impractical though, and the different cases
 of odd and even length strings add complexity.&nbsp; Abandoned this....<br>
<br>
5.&nbsp; Next idea was to start with pointers at both ends and work my way towards the middle, comparing as I go.&nbsp; I added a while/compare to skip spaces.&nbsp; Code follows:<br>
<br>
bool IsPalindrome(TCHAR* tcstring)<br>
{<br>
&nbsp;if(tcstring==NULL|| *tcstring==NULL) return false;<br>
&nbsp;TCHAR* first=tcstring;<br>
&nbsp;TCHAR* last=(tcstring&#43;_tcsclen(tcstring)-1);<br>
&nbsp;TCHAR space=*_T(&quot; &quot;);</p>
<p>&nbsp;while(1)<br>
&nbsp;{<br>
&nbsp;&nbsp;if(*first!=*last)<br>
&nbsp;&nbsp;&nbsp;return false;<br>
&nbsp;&nbsp;while(*(&#43;&#43;first)==space);<br>
&nbsp;&nbsp;while(*(--last)==space);<br>
&nbsp;if(last&lt;=first)<br>
&nbsp;&nbsp;return true;<br>
&nbsp;<br>
&nbsp;}&nbsp; <br>
}<br>
<br>
Now I wasn't quite happy with having to use the built-in _tcsclen, but this does provide a relatively efficient result, and I managed to work in the ignoring of spaces, and I checked for null strings and null pointers.<br>
<br>
6.&nbsp; In an effort to make the solution a little more &quot;pure&quot;, I decided to manually traverse the list, looking for the null, and then work my way half-way backwards checking as I go backwards. Code follows:<br>
<br>
bool IsPalindrome(TCHAR* tcstring)<br>
{<br>
&nbsp;if(tcstring==NULL|| *tcstring==NULL) return false;<br>
&nbsp;TCHAR* ptr=tcstring;<br>
&nbsp;TCHAR* halfptr;<br>
&nbsp;while(*(&#43;&#43;ptr)!=NULL);<br>
&nbsp;halfptr=tcstring&#43;(ptr-tcstring)/2;<br>
&nbsp;while(*(tcstring&#43;&#43;) == *(--ptr) &amp;&amp; ptr&gt;halfptr);<br>
&nbsp;if(*(--tcstring) == *ptr) return true;&nbsp;<br>
&nbsp;return false;<br>
}<br>
<br>
I like this solution for its efficiency, even though it won't handle spaces, case, or punctuation.&nbsp; I could handle any of those by expanding the while loops.<br>
<br>
7.&nbsp; Lastly, I thought I'd see if I could gain anything by trying the typicalyl gimmicky recursion method.&nbsp; Code follows:
<br>
<br>
bool IsPalindromeHelper(TCHAR* first, TCHAR* last)<br>
{<br>
&nbsp;if(first&gt;=last) return true;<br>
&nbsp;if(*first!=*last) return false;<br>
&nbsp;return(IsPalindromeHelper(first&#43;1,last-1));<br>
}</p>
<p><br>
bool IsPalindrome(TCHAR* thestr)<br>
{<br>
&nbsp;TCHAR* last=thestr;<br>
&nbsp;while(*(&#43;&#43;last)!=NULL);<br>
&nbsp;return(IsPalindromeHelper(thestr,--last));<br>
}<br>
<br>
While the recursion adds a bit of a &quot;cool&quot; factor to the solution, it doesn't handle spaces or case, and you have the added overhead of the recursive call, so I don't think it's quite worth it.<br>
<br>
8.&nbsp; I'd probably go back to my second solution, and work in any requirements for spaces / case insensitivity. (and add comments of course!)<br>
<br>
9.&nbsp; For preliminary testing, I'd include null pointers, invalid pointers, null strings, non-terminated strings, even-length palindromes, odd-length palindromes, even and odd length non-palindromes, near palindromes with differences at the beginning/end, near
 palindromes with differences at the middle two chars&nbsp;for even length, and differences at &#43;/-1 from middle for odd length.&nbsp; Palindromes and non-palindromes of length 1,2, 3, and very large palindrome and non-palindrome inputs of lengths 2^10, 2^16-1,2^16,2^16&#43;1,
 2^32-1,2^32, 2^32&#43;1, etc.&nbsp; Also test palindromes that excercise any of the special requirements, i.e. spaces, punctuation, etc...&nbsp; Include these special chars at beginning/end/middle...</p>
<p>posted by RickH</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290370920000000</link>
		<pubDate>Wed, 25 Aug 2004 13:24:52 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290370920000000</guid>
		<dc:creator>RickH</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Thanks for the tips!!!<br>
<br>
Is it <strong>Palendrome</strong> or <strong>Palindrome</strong>?&nbsp;&nbsp; Anyway here is my C# version using Recursion.<br>
<br>
<br>
<br>
<p>public bool isPalindrome(String s) </p>
<p>{</p>
<p>if ( s.Length &lt;= 1 ) return true;</p>
<p>if ( s.EndsWith(s.Substring(0,1) )) </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; return isPalindrome( s.Substring(1, s.Length - 2 ) );</p>
<p>return false;</p>
<p>}</p>
<br>
<p>posted by Anonieko Ramos</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290395860000000</link>
		<pubDate>Wed, 25 Aug 2004 14:06:26 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290395860000000</guid>
		<dc:creator>Anonieko Ramos</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[RickH asked what is to me at least a crucial question: What would be the properties of a good solution. Knowing what to aim for is crucial.<br>
Maybe it is the C angle that has most here assuming that &quot;speed &amp; space&quot;&nbsp;are the top desirable characteristics.
<br>
<br>
Personally I would rather have the candidates&nbsp;assume security, clarity and maintainability by default, and only go for increased efficiency as a sort of second coming. Better to ask though.<br>
<br>
Finding out that the application domain for your little function is testing multi gigabyte strings stored on sequential access media after you have written the code might be a sort of &quot;Duh!&quot; moment.<p>posted by Peter</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290480300000000</link>
		<pubDate>Wed, 25 Aug 2004 16:27:10 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290480300000000</guid>
		<dc:creator>Peter</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>Peter wrote:</div>
<div>Finding out that the application domain for your little function is testing multi gigabyte strings stored on sequential access media after you have written the code might be a sort of &quot;Duh!&quot; moment.</div>
</blockquote>
<br>
<br>
Indeed!<br>
In that case, other algorithms present themselves.&nbsp; The immediate solution seems to be &quot;slurp everything into memory and pray the virtual memory doesn't run out&quot;, but if this fails there are fallbacks.<br>
<br>
Do we know the size of the string in advance?&nbsp; Is there a way for us to determine which media the nth character of the string is on?&nbsp; Are all characters significant?&nbsp; (That is, is the nominal middle the same as the palindromic middle?)<br>
<br>
If all these three things are true you can read from the media holding character (length / 2) out.&nbsp; If the string is not a palindrome, it is very likely you won't need to read any other media.<br>
<br>
I must also note that at some point complexity of code becomes an issue.&nbsp; If the solution is over-optimized (yes, there is such a thing) it becomes very easy to introduce bugs when maintenance is required.&nbsp; As a user, I would rather have a solution without
 bugs than a solution that saved me a few media swaps.<br>
<br>
Also, complex solutions are slow to develop.&nbsp; If there's competition in the marketplace, speed to release may be a factor.&nbsp; There's a lot to be said for keeping it simple.<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290523330000000</link>
		<pubDate>Wed, 25 Aug 2004 17:38:53 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290523330000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[I'd do it in C in any of the three ways I did it here: <br>
<br>
<b>First Way</b><br>
<br>
#include&lt;stdio.h&gt;<br>
#include &lt;string.h&gt;<br>
<br>
int IsPallindrome(char*);<br>
<br>
int main()<br>
{<br>
&nbsp;&nbsp;&nbsp; int bRetVal =0;<br>
<br>
&nbsp;&nbsp;&nbsp; char str[100];<br>
&nbsp;&nbsp;&nbsp; printf(&quot;Enter a word: &quot;);<br>
&nbsp;&nbsp;&nbsp; scanf(&quot;%s&quot;, &amp;str);<br>
&nbsp;&nbsp;&nbsp; bRetVal= IsPallindrome(str);<br>
&nbsp;&nbsp;&nbsp; if (bRetVal==1)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%s is a pallindrome.\n&quot;, str);<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%s is not a pallindrome. \n&quot;, str);<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; return 0;<br>
}<br>
<br>
int IsPallindrome(char* str)<br>
{<br>
<br>
&nbsp;&nbsp;&nbsp; int i, j, len;<br>
&nbsp;&nbsp;&nbsp; i=j=len=0;<br>
<br>
&nbsp;&nbsp;&nbsp; //the string is not null<br>
&nbsp;&nbsp;&nbsp; if (str==NULL) return 0;<br>
<br>
&nbsp;&nbsp;&nbsp; //It might just have a null-terminator and no contents. Zero length string.<br>
&nbsp;&nbsp;&nbsp; if ((len=strlen(str))==0) return 0;<br>
<br>
&nbsp;&nbsp;&nbsp; for(i=0, j=len-1; i&lt;=j; i&#43;&#43;, j--)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(*(str&#43;i) != *(str&#43;j)) <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return 0;<br>
<br>
&nbsp;&nbsp;&nbsp; return 1;<br>
}<br>
<br>
<br>
<b>Second Way</b><br>
<br>
I'd copy the string in place to another memory location <a href="http://discuss.fogcreek.com/techinterview/default.asp?cmd=show&amp;ixPost=2077&amp;ixReplies=8">
and simply reverse it</a>, and check if they are identical.<br>
<br>
<br>
<a href="http://www.codeguru.com/forum/showthread.php?t=293945"><b>Third Way</b></a><br>
<br>
<br>
<b>Design Goals</b><br>
<br>
No checking for spaces, because a space thing opens up two different options:<br>
<ol>
<li>Under this scheme, the text, &quot;Mal Ayal Am&quot; would be a pallindrome&nbsp; because if you prun the spaces, it reads the same forwards and backwards. In such a case it would be correct to first trim the spaces inside the string and outside it (leading and trailing)
 and then use the IsPallindrome function above on the resultant string.<br>
</li><li>However, if you do not ignore the spaces, it is not a pallindrome because the spaces encountered in a forward traversal do not coincide with the spaces encountered backward. In such a case, the above mentioned IsPallindrome should yeild the correct results.<br>
</li></ol>
<br>
<b>Notes: </b><br>
<br>
(1) I've used scanf which should stop reading after a white space. I might have used getline as well, and that'd have been better.<br>
(2) The comparison done here is Binary and not Text based, so &quot;Pop&quot; won't be a pallindrome but &quot;PoP&quot; will be, The alternative TextBased solution would have either used LCase or Ucase functions or just a transpose of the ASCII values by adding or subtracting
 32 for the alphanumeric keys.<br>
<br>
A Visual Basic solution is even simpler:<br>
<br>
Public Function IsPallindrome(ByVal StrWord As String) As Boolean<br>
&nbsp;&nbsp;&nbsp; IsPallindrome = (StrComp(Trim(StrWord), Trim(StrReverse(StrWord)), vbBinaryCompare) = 0)<br>
End Function<br>
<br>
Private Sub Command1_Click()<br>
&nbsp;&nbsp;&nbsp; MsgBox Text1.Text &amp; IIf(IsPallindrome(Text1.Text), &quot; is&quot;, &quot; is not&quot;) &amp; &quot; a pallindrome.&quot;<br>
End Sub<br>
<p>posted by Sathyaish Chakravarthy</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290662250000000</link>
		<pubDate>Wed, 25 Aug 2004 21:30:25 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290662250000000</guid>
		<dc:creator>Sathyaish Chakravarthy</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>Sathyaish Chakravarthy wrote:</div>
<div><br>
&nbsp;&nbsp;&nbsp; //It might just have a null-terminator and no contents. Zero length string.<br>
&nbsp;&nbsp;&nbsp; if ((len=strlen(str))==0) return 0;<br>
</div>
</blockquote>
<br>
<br>
I've seen a lot of people do this but yours was a convenient example.<br>
The more I think about it, the more I think that zero-length strings ARE palindromes.&nbsp; This is especially important in recursive algorithms applied to even-length strings.<br>
NULL strings, on the other hand - in languages where there is a distinction - are another matter.<br>
<br>
These are exceptional cases, of course, and of secondary importance.<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290688740000000</link>
		<pubDate>Wed, 25 Aug 2004 22:14:34 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290688740000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>Maurits wrote:</div>
<div>
<blockquote>
<table>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</blockquote>
The more I think about it, the more I think that zero-length strings ARE palindromes.&nbsp; This is especially important in recursive algorithms applied to even-length strings.<br>
</div>
</blockquote>
<br>
<br>
Could you please elaborate?<br>
<p>posted by Sathyaish Chakravarthy</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290703230000000</link>
		<pubDate>Wed, 25 Aug 2004 22:38:43 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290703230000000</guid>
		<dc:creator>Sathyaish Chakravarthy</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>I would tackle the palindrome problem in this manner. Opinions on the code and complexity are welcome <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' />:</p>
<p>Input:<br>
Characters, Numbers, Alphanumerics, White Spaces, Wildcards.<br>
----</p>
<p>Example Test Cases:<br>
tarat, ta r at, tar at, ta 1 at, ab 1A1 ba, ab1A 1ba etc (The code considers them correct inputs).<br>
Ta a, ta 1 ata, etc are not palindromes. <br>
----</p>
<p>Output:<br>
True or False<br>
----</p>
<p>Algorithm:<br>
To acheive efficient memory management, computation time and code complexity, I would parse through the text from the two
</p>
<p>corners ie begining and end and reach the center of the text while comparing each of the input characters. There would be
</p>
<p>checks for white spaces. Other characters such as commas, appostrophies etc would be considered as character inputs. If it
</p>
<p>encounters white spaces, it would ignore them and (increment the begining counter or decrement the end counter).</p>
<p>Other implementation such as a recursive one would require extra stack space and recursive calls to the heap. Which might
</p>
<p>not be a good idea. Reversing the string and comparing with the original one would also not be a good idea as extra memory
</p>
<p>would be required. </p>
<p>Pseudocode:<br>
-Initilize all variables ie int beg, end, bool check variables.</p>
<p>-point the beg pointer to the first character of the input string.</p>
<p>-Find length of string and point the 'end pointer' to the (str_len - 1)th position.</p>
<p>-Enter a while loop and compare the beg and end. </p>
<p>---If they are equal, do beg&#43;&#43; and end--. </p>
<p>---if they are not, check for white spaces, ignore white spaces, and inc or dec accordingly ie if beg, inc beg and leave end
</p>
<p>as it is, OR, if it is end, than dec end and leave beg to point to where it is pointing.
</p>
<p>----if they are still not equal, return FALSE.</p>
<p>-end of program.<br>
----</p>
<p>Complexity:<br>
The complexity of the code would be O(n) where n is the length of the input string. In reality, the code would run for n/2
</p>
<p>iterations as when the beg pointer reaches the middle&#43;1th part of the string, it would stop the while loop.
</p>
<p>Code:</p>
<p>#include &lt;iostream.h&gt;<br>
#include &lt;string.h&gt;</p>
<p>bool ispalin(char * input)<br>
{<br>
&nbsp;char * beg=new char;<br>
&nbsp;char * end = new char;<br>
&nbsp;<br>
&nbsp;beg = input;<br>
&nbsp;end = &amp;input[strlen(input)-1];<br>
&nbsp;<br>
&nbsp;if(beg==0 || beg==NULL)<br>
&nbsp;&nbsp;return false;<br>
&nbsp;<br>
&nbsp;while(*beg==*end &amp;&amp; *beg != input[strlen(input)/2])<br>
&nbsp;{<br>
&nbsp;&nbsp;if(*beg == ' ')<br>
&nbsp;&nbsp;&nbsp;beg&#43;&#43;;<br>
&nbsp;&nbsp;if(*end = ' ')<br>
&nbsp;&nbsp;&nbsp;end--;<br>
&nbsp;&nbsp;if(beg!=end)<br>
&nbsp;&nbsp;&nbsp;return false;<br>
&nbsp;&nbsp;if(beg==end)<br>
&nbsp;&nbsp;&nbsp;return true;</p>
<p>&nbsp;&nbsp;beg&#43;&#43;;<br>
&nbsp;&nbsp;end--;<br>
&nbsp;}<br>
&nbsp;</p>
<p>}</p>
<p>int main()<br>
{<br>
&nbsp;bool check=false;<br>
&nbsp;char * input = new char[30];<br>
&nbsp;cin.getline(input, 30, '\n');//as cin.getline caters to white spaces as well<br>
&nbsp;check = ispalin(input);</p>
<p>&nbsp;if(check==0)<br>
&nbsp;{<br>
&nbsp;&nbsp;cout&lt;&lt;&quot;equal\n&quot;;<br>
&nbsp;}<br>
&nbsp;else<br>
&nbsp;&nbsp;cout&lt;&lt;&quot;not equal\n&quot;;</p>
<p>&nbsp;return 0;<br>
}<br>
-------</p>
<p>posted by tashfeen_suleman</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290741670000000</link>
		<pubDate>Wed, 25 Aug 2004 23:42:47 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290741670000000</guid>
		<dc:creator>tashfeen_suleman</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>Sathyaish Chakravarthy wrote:</div>
<div><br>
A Visual Basic solution is even simpler:<br>
<br>
Public Function IsPallindrome(ByVal StrWord As String) As Boolean<br>
&nbsp;&nbsp;&nbsp; IsPallindrome = (StrComp(Trim(StrWord), Trim(StrReverse(StrWord)), vbBinaryCompare) = 0)<br>
End Function<br>
<br>
Private Sub Command1_Click()<br>
&nbsp;&nbsp;&nbsp; MsgBox Text1.Text &amp; IIf(IsPallindrome(Text1.Text), &quot; is&quot;, &quot; is not&quot;) &amp; &quot; a pallindrome.&quot;<br>
End Sub<br>
</div>
</blockquote>
<br>
<br>
Yes, that Visual Basic Solution is even simpler, but it also has alot slower performance. It is alot faster to go through and check each character, than to make a reverse copy of the whole string and compare it.<p>posted by CRPietschmann</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290756600000000</link>
		<pubDate>Thu, 26 Aug 2004 00:07:40 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290756600000000</guid>
		<dc:creator>CRPietschmann</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[I am not even debating that the Visual Basic solution would be slower than the C code.<br>
<p>posted by Sathyaish Chakravarthy</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290760630000000</link>
		<pubDate>Thu, 26 Aug 2004 00:14:23 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290760630000000</guid>
		<dc:creator>Sathyaish Chakravarthy</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>// Quickie C&#43;&#43; - worked the first time.&nbsp; <br>
// Easier than the whiteboard question I got in <br>
// my MSFT interview.<br>
//<br>
// Oh yeah, this version ignores spaces just <br>
// for grins.<br>
//<br>
#include &lt;cassert&gt;</p>
<p>template &lt;<br>
&nbsp;&nbsp;&nbsp;typename RandIt,&nbsp;<br>
&nbsp;&nbsp;&nbsp;typename CharT,&nbsp;<br>
&nbsp;&nbsp;&nbsp;CharT space<br>
&nbsp;&nbsp;&nbsp;&gt;<br>
bool IsPalindrome(RandIt start, RandIt end)<br>
{<br>
&nbsp;end--;<br>
&nbsp;do<br>
&nbsp;{<br>
&nbsp;&nbsp;while (space == *start)<br>
&nbsp;&nbsp;&nbsp;start&#43;&#43;;<br>
&nbsp;&nbsp;while (space == *end)<br>
&nbsp;&nbsp;&nbsp;end--;<br>
&nbsp;&nbsp;if (end &lt; start)<br>
&nbsp;&nbsp;&nbsp;return false;<br>
&nbsp;&nbsp;if (*start != *end)<br>
&nbsp;&nbsp;&nbsp;return false;<br>
&nbsp;&nbsp;start&#43;&#43;;<br>
&nbsp;&nbsp;end--;<br>
&nbsp;&nbsp;<br>
&nbsp;} while (start&lt;end);<br>
&nbsp;return true;<br>
}</p>
<p>bool IsPalindrome(const char* str)<br>
{<br>
&nbsp;assert(str);<br>
&nbsp;return IsPalindrome&lt;const char*,char,' '&gt;(<br>
&nbsp;&nbsp;&nbsp;str,<br>
&nbsp;&nbsp;&nbsp;str&#43;strlen(str)<br>
&nbsp;&nbsp;&nbsp;);<br>
}<br>
</p>
<p>posted by cpdaniel</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290817870000000</link>
		<pubDate>Thu, 26 Aug 2004 01:49:47 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290817870000000</guid>
		<dc:creator>cpdaniel</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[here is an updated version of the code i pasted before. it can handle all characters and white spaces or a mix of everything together <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' />. the thing i would like the most is a technical clarification on a palindrome so we can build off of what they REALLY
 are and not our guesses =/. i reinvented the wheel on the Reverse() rather than using reverse() in the STL algorithm class so it would be a tad more challanging and fun to do. for space reasons, code organization and stuff like that i put it up on a code pasting
 site =). the link can be found here -&gt; <a href="http://rafb.net/paste/results/1zLtoc63.html">
http://rafb.net/paste/results/1zLtoc63.html</a><p>posted by goodeffort</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290855360000000</link>
		<pubDate>Thu, 26 Aug 2004 02:52:16 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290855360000000</guid>
		<dc:creator>goodeffort</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[// Not a performance or memory effective and does not work with punctuation<br>
// But it's pretty easy to maintain and cool C&#43;&#43; code I can not keep private <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /><br>
<br>
bool IsPalindrome(TCHAR* buff) {<br>
&nbsp;if(NULL==buff) return false;<br>
<br>
&nbsp;<a href="http://msdn.microsoft.com/library/en-us/vclib/html/vclrfCStringT.asp">CString</a> chars(buff);<br>
&nbsp;return chars.<a href="http://msdn.microsoft.com/library/en-us/vclib/html/vclrfCStringTMakeReverse.asp">MakeReverse</a>().<a href="http://msdn.microsoft.com/library/en-us/vclib/html/vclrfCStringTCollateNoCase.asp">CollateNoCase</a>(buff)==0<strong>;</strong><br>
}<p>posted by AT</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290973070000000</link>
		<pubDate>Thu, 26 Aug 2004 06:08:27 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632290973070000000</guid>
		<dc:creator>AT</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[<b>boneman: </b>all that girly detailed stuff will be taken care of in a service pack! Let these burly men sling brains!<br>
<br>
I'm surpised we haven't seen the use of regular expressions...<br>
<p>posted by rasx</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291002980000000</link>
		<pubDate>Thu, 26 Aug 2004 06:58:18 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291002980000000</guid>
		<dc:creator>rasx</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>I love this kind of exercies <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-2.gif' alt='Big Smile' />. Here is my solution<br>
<br>
</p>
<p>private bool IsYalendrome2(string t)<br>
{<br>
&nbsp;&nbsp;&nbsp;if(t == null || t.Length == 0)<br>
&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp;bool r = true;<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;for(int i = 0, n = t.Length -1; i &lt; n &amp;&amp; r; i&#43;&#43;, n--)<br>
&nbsp;&nbsp;&nbsp;&nbsp; r = t[i] == t[n];<br>
<br>
&nbsp;&nbsp;&nbsp;return r;<br>
}<br>
<br>
I like the XML-Blog solution (it's very elegant), but i think this one is a little more readable, and i think that's is one of the goal we (as developers) have to take care.<br>
<br>
Anyway: B# use C# ;-D<br>
<br>
</p>
<p>posted by ezu</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291124030000000</link>
		<pubDate>Thu, 26 Aug 2004 10:20:03 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291124030000000</guid>
		<dc:creator>ezu</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>Sathyaish Chakravarthy wrote:</div>
<div>
<blockquote>
<table>
<tbody>
<tr>
<td><img src="/Themes/redesign/images/icon-quote.gif"></td>
<td><strong>Maurits wrote:</strong><i>
<blockquote>
<table>
<tbody>
<tr>
<td><br>
</td>
<td><br>
</td>
</tr>
</tbody>
</table>
</blockquote>
The more I think about it, the more I think that zero-length strings ARE palindromes.&nbsp; This is especially important in recursive algorithms applied to even-length strings.<br>
</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br>
<br>
Could you please elaborate?<br>
</div>
</blockquote>
<br>
<br>
OK.&nbsp; One algorithm I've seen is:<br>
Is_Palindrome:<br>
&nbsp; If the string length is 0, return TRUE *<br>
&nbsp; If the string length is 1, return TRUE<br>
&nbsp; If the first character is different than the last character, return FALSE<br>
&nbsp; Otherwise, recursively check the string minus the first and last character<br>
<br>
The *'d line is what I'm referring to.&nbsp; If the TRUE is changed to a FALSE, then every even-length palindrome will incorrectly return FALSE.<br>
<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291374450000000</link>
		<pubDate>Thu, 26 Aug 2004 17:17:25 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291374450000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>rasx wrote:</div>
<div><b></b><br>
I'm surpised we haven't seen the use of regular expressions...<br>
</div>
</blockquote>
<br>
<br>
You didn't see my javascript solution?&nbsp; I used a regular expression to test for interestingness of characters.<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291378300000000</link>
		<pubDate>Thu, 26 Aug 2004 17:23:50 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291378300000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p dir="ltr">I feel that functional languages haven't been well represented. This is Scheme code:<br>
<br>
(define (palindrome? s)<br>
&nbsp; (define (iter s)<br>
&nbsp;&nbsp;&nbsp; (cond ((equal? (length s) 0) #t)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((equal? (length s) 1) #t)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((equal? (car s) (car (reverse s)))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (iter (reverse (cdr (reverse (cdr s))))))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (else #f)))<br>
&nbsp; (iter (string-&gt;list s)))<br>
<br>
Feel the elegance =)</p>
<p>posted by MattK</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291434630000000</link>
		<pubDate>Thu, 26 Aug 2004 18:57:43 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291434630000000</guid>
		<dc:creator>MattK</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Unfortunately, you can't use a regular expression to check for every palindrome. This is because the &quot;language of palindromes&quot; isn't a regular language.<br>
<br>
You should be able to read more about this in a textbook that covers formal language theory. This includes a lot of textbooks which cover parsing and compilation.<p>posted by MattK</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291447350000000</link>
		<pubDate>Thu, 26 Aug 2004 19:18:55 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291447350000000</guid>
		<dc:creator>MattK</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Decided to try and cook up a solution. Did some testing, it handled all the test cases I threw at it correctly. It's not exactly a pretty solution, but eh.<br>
<pre>#include &lt;list&gt;<br>
inline bool isAlphanumeric(_TCHAR ch) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;return ((ch &gt;= 'a') &amp;&amp; (ch &lt;= 'z') || (ch &gt;= 'A') &amp;&amp; (ch &lt;= 'Z') || (ch &gt;= '0') &amp;&amp; (ch &lt;= '9'));<br>
}<br>
int isPalindrome(_TCHAR* string) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;// init<br>
&nbsp;&nbsp;&nbsp;&nbsp;if (string == 0) return -1;<br>
&nbsp;&nbsp;&nbsp;&nbsp;_TCHAR *c = string;<br>
&nbsp;&nbsp;&nbsp;&nbsp;std::list&lt;_TCHAR&gt; stack;<br>
&nbsp;&nbsp;&nbsp;&nbsp;// build stack<br>
&nbsp;&nbsp;&nbsp;&nbsp;while (*c != 0)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stack.push_back(*c&#43;&#43;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;_TCHAR a, b;<br>
&nbsp;&nbsp;&nbsp;&nbsp;while (stack.size() &gt; 1) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// pull the start and end items off the stack<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a = stack.front(); b = stack.back();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stack.pop_front(); stack.pop_back();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (a != b) return 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// they are both equal so just test one<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!isAlphanumeric(a)) return 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;// if the middle character is not alphanumeric the stack scanning algorithm won't catch it, so check<br>
&nbsp;&nbsp;&nbsp;&nbsp;if ((stack.size() &gt; 0) &amp;&amp; (!isAlphanumeric(stack.back()))) return 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;return 1;<br>
}</pre>
<p>posted by Kaelan</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291502440000000</link>
		<pubDate>Thu, 26 Aug 2004 20:50:44 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291502440000000</guid>
		<dc:creator>Kaelan</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>MattK wrote:</div>
<div>Unfortunately, you can't use a regular expression to check for every palindrome. This is because the &quot;language of palindromes&quot; isn't a regular language.</div>
</blockquote>
<br>
<br>
Not directly.&nbsp; That is, there isn't a single regular expression that detects palindromes - or to put it another way, no value of ... will make this function work:<br>
<br>
# Perl - this function doesn't work<br>
sub is_palindrome($)<br>
{&nbsp;&nbsp; return shift =~ /.../;<br>
}<br>
<br>
But regular expressions can be used as part of a larger tool.&nbsp; This function does work (unfortunately it's still katana-sensitive...)<br>
<br>
# Perl - this function does work but still doesn't equate ñ with n<br>
sub is_palindrome($)<br>
{&nbsp;&nbsp; my $string = shift;<br>
<br>
&nbsp;&nbsp;&nbsp; # Strip out uninteresting characters<br>
&nbsp;&nbsp;&nbsp; # The following line assumes only a-z and A-Z are interesting<br>
&nbsp;&nbsp;&nbsp; $string =~ s/[^a-z]//ig;<br>
<br>
&nbsp;&nbsp;&nbsp; # Make lowercase letters uppercase<br>
&nbsp;&nbsp;&nbsp; $string =~ tr/a-z/A-Z/;<br>
<br>
&nbsp;&nbsp;&nbsp; # if the string equals it's reverse then it's a palindrome<br>
&nbsp;&nbsp;&nbsp; return $string eq reverse $string;<br>
}<br>
<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291505850000000</link>
		<pubDate>Thu, 26 Aug 2004 20:56:25 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291505850000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>MattK wrote:</div>
<div>
<p dir="ltr">I feel that functional languages haven't been well represented. This is Scheme code:<br>
<br>
(define (palindrome? s)<br>
&nbsp; (define (iter s)<br>
&nbsp;&nbsp;&nbsp; (cond ((equal? (length s) 0) #t)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((equal? (length s) 1) #t)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((equal? (car s) (car (reverse s)))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (iter (reverse (cdr (reverse (cdr s))))))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (else #f)))<br>
&nbsp; (iter (string-&gt;list s)))<br>
<br>
Feel the elegance =)</p>
</div>
</blockquote>
<br>
<br>
OK, now make it handle spaces.<br>
Kind of makes you wish that ( and ) were home-row, huh?<br>
(devilish-grin)<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291509620000000</link>
		<pubDate>Thu, 26 Aug 2004 21:02:42 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291509620000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>I think this one is a good candidate (threats space as an ordinary char). Feel free to use it <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /><br>
<br>
<br>
public static bool IsPalindrome(string s)<br>
{<br>
&nbsp;&nbsp;&nbsp; if(null == s)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; for(int f=0, b = s.Length - 1; f &lt; b; f&#43;&#43;, b--) <br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(s[f] != s[b])<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; return true;<br>
}<br>
<br>
Cheers Martin, with a phone number in palindrome...cool huh?</p>
<p>posted by ML</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291517710000000</link>
		<pubDate>Thu, 26 Aug 2004 21:16:11 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291517710000000</guid>
		<dc:creator>ML</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[I hate to be a ball buster to all those who have provided their solutions for the palindrome problem but I was able to solve&nbsp;the problem&nbsp;in less than 5 minutes using Visual Basic.Net.<br>
<br>
Even the Visual Basic solutions that I read were, in my opinion, over-analyzed!<br>
<br>
You guys are overthinking things. What I try to do when I code is to think about a problem in terms of SIMPLICITY. Have we all forgotten the cliche? KISS - keep is simple stupid!<br>
<br>
Sounds like those of you who are using VB.Net need to be MORE aware of the incredibly power FUNCTIONS that are included in the current version of Visual Studio. It makes all the difference in the world...<br>
<br>
Here is the VB code I've come up with - it's 5 lines:<br>
-------------------<br>
If Me.txt1.Text = StrReverse(Me.txt1.Text) Then
<p>Me.txt2.Text = &quot;True&quot;</p>
<p>Else</p>
<p>Me.txt2.Text = &quot;False&quot;</p>
<p>End If<br>
---------------------------<br>
<br>
The code entails 3 objects - 2 text boxes and a button. Attach the code to a button control and
<br>
you are done.<br>
<br>
The code handles punctuation, nulls, whitespaces and is even case sensitive meaning, this code recognizes case sensitive palindromes, so AbBa would not be considered a palindrome using this algorithm.<br>
<br>
Now, depending on what side of the philosophical argument you are on in terms of what constitutes a palindrome relative to upper and lower case letters, the code I provided can be minimally tweaked to accommodate the palindrome for either interpretation. All
 that is needed to recognize mixed case palindromes is to integrate an additional function (UCase) to the mix.<br>
<br>
I found this problem interesting but fairly easy to solve.</p>
<p>posted by Brice It</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291578570000000</link>
		<pubDate>Thu, 26 Aug 2004 22:57:37 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291578570000000</guid>
		<dc:creator>Brice It</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>Brice It wrote:</div>
<div><br>
I found this problem interesting but fairly easy to solve.</div>
</blockquote>
<br>
<br>
That's the obvious answer, but has several flaws. It's very memory hungry and requires multiple iterations through the string.
<br>
<br>
The easy, efficient way is a single pass through the string, comparing first/last characters (ignoring whitespace/punctuation as required). FWIW, that solution took less than 5 minutes to arrive at.<br>
<br>
Since everyone's posted that though, I'll go with.<br>
<br>
stack s<br>
queue q<br>
<br>
for (i = 0;i &lt; str.Length; i&#43;&#43;)<br>
{<br>
&nbsp;&nbsp;&nbsp;if&nbsp;str[i] != whitespace<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q.enqueue(str[i])<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.push(str[i])<br>
&nbsp;&nbsp;&nbsp;}<br>
}<br>
<br>
palindrome=true<br>
while (!(q.Empty))<br>
{<br>
&nbsp;&nbsp;&nbsp;if q.dequeue != s.pop then palindrome = false<br>
}<br>
<p>posted by AndyC</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291608720000000</link>
		<pubDate>Thu, 26 Aug 2004 23:47:52 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291608720000000</guid>
		<dc:creator>AndyC</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>AndyC:::<br>
<br>
You may be correct in your analysis regarding memory allocation within my proposed solution but that was not part of the initial problem.<br>
<br>
The challenge was to come up with a coding algorithm that could parse text to determine whether or not a palindrome existed.<br>
<br>
No one said anything about memory requirements within the solution.<br>
<br>
AS technology advances, memory allocation issues will slowly begin to become a non-issue in programming in my view.<br>
<br>
The future programmer needs to focus on understanding namespaces, classes, functions, and object thinking rather than whether or not memory has been optimized within a given algorithm.</p>
<p>posted by Brice It</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291670480000000</link>
		<pubDate>Fri, 27 Aug 2004 01:30:48 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291670480000000</guid>
		<dc:creator>Brice It</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>This was a fun way to kill an hour - thanks!<br>
<br>
<br>
using System;</p>
<p>using System.Collections.Generic;</p>
<p>#endregion</p>
<p>namespace IsPalindrome</p>
<p>{</p>
<p>&nbsp; using System.Globalization;</p>
<p>&nbsp; using System.Text;</p>
<p>&nbsp; class Program</p>
<p>&nbsp; {</p>
<p>&nbsp;&nbsp;&nbsp; static void Main(string[] args)</p>
<p>&nbsp;&nbsp;&nbsp; {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Program program = new Program();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;IsPalindrome method passes: &quot; &#43; program.testIsPalindrome().ToString());</p>
<p>&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; bool IsPalindrome(String candidate)</p>
<p>&nbsp;&nbsp;&nbsp; {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return IsPalindrome(candidate, CultureInfo.CurrentCulture);</p>
<p>&nbsp;&nbsp;&nbsp; }</p>
<p>/// &lt;summary&gt;</p>
<p>/// From m-w.com, definition of Palindrome: a word, verse, or sentence (as &quot;Able was I ere I saw Elba&quot;) or a number (as 1881) that reads the same backward or forward.</p>
<p>/// For the purposes of this method, a palindrome is a string whose component characters &quot;read&quot; the same</p>
<p>/// forwards or backwards, ignoring whitespace, punctuation, and control. Whether it means anything in the</p>
<p>/// target language is, unfortunately, ignored! But it should work with strings of any culture.</p>
<p>/// A null culture is assumed to mean the current culture.</p>
<p>/// A null or zero-length candidate string is not considered a palindrome.</p>
<p>/// &lt;/summary&gt;</p>
<p>/// &lt;returns&gt;&lt;/returns&gt;</p>
<p>&nbsp;&nbsp;&nbsp; bool IsPalindrome(String candidate, CultureInfo culture)</p>
<p>&nbsp;&nbsp;&nbsp; {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (null == candidate)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false; // null candidates are not palindromes.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (candidate.Length == 0)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false; // zero-length candidates are not palindromes</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (null == culture)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; culture = CultureInfo.CurrentCulture; // use the default if a null was provided.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StringBuilder blackStringB = new StringBuilder(candidate.Length); // black string; no whitespace.</p>
<p>// remove whitespace, punctuation, control characters; they don't count towards palindromes.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; candidate.Length; i&#43;&#43;)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!Char.IsWhiteSpace(candidate, i)</p>
<p>&amp;&amp; !Char.IsPunctuation(candidate, i)</p>
<p>&amp;&amp; !Char.IsControl(candidate, i))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blackStringB.Append(candidate, i, 1);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>// now we have no whitespace.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (blackStringB.Length == 0)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false; // zero-length candidates are not palindromes</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String blackString = blackStringB.ToString().ToUpper(culture);</p>
<p>// we've removed case sensitivity by converting all characters to upper case.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int length = blackString.Length;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; length / 2; i&#43;&#43;)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (0 != blackString[i].CompareTo(blackString[(length - i) - 1]))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true;</p>
<p>&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; bool testIsPalindrome()</p>
<p>&nbsp;&nbsp;&nbsp; {</p>
<p>// palindromes </p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;a&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;aA&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;aa&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;aaa&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;2a7a2&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;if (!IsPalindrome(&quot;aaaa&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;aBa&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;a Ba&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;aB a&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;a.Ba?&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;A B?; a?&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;Able was I ere I saw Elba&quot;, CultureInfo.CurrentCulture)) // Napoleon, we hardly knew ye.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(&quot;A man, a plan, a canal: Panama!&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; StringBuilder sb = new StringBuilder();</p>
<p>&nbsp;&nbsp;&nbsp; sb.Append(Char.MinValue);</p>
<p>&nbsp;&nbsp;&nbsp; sb.Append(Char.MaxValue);</p>
<p>&nbsp;&nbsp;&nbsp; sb.Append(Char.MinValue);</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(sb.ToString(), CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(GeneratePalindrome()))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;if (!IsPalindrome(GeneratePalindrome()))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (!IsPalindrome(GeneratePalindrome()))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>// not palindromes</p>
<p>&nbsp;&nbsp;&nbsp; if (IsPalindrome(&quot;oiiunrviuhnuiycgcbzsrucgckjzsehbcuycu33ndjdjdj&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (IsPalindrome(&quot;67__32&#43;&#43;7S'&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (IsPalindrome(&quot;ab&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (IsPalindrome(&quot;aB&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (IsPalindrome(&quot;&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (IsPalindrome(null, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; if (IsPalindrome(&quot;A man, a plan, a canal: Suez?&quot;, CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; sb = new StringBuilder(); // check a string that can't be a palindrome with end chars.</p>
<p>&nbsp;&nbsp;&nbsp; sb.Append(Char.MinValue);</p>
<p>&nbsp;&nbsp;&nbsp; sb.Append(Char.MaxValue);</p>
<p>&nbsp;&nbsp;&nbsp; sb.Append('a');</p>
<p>&nbsp;&nbsp;&nbsp; sb.Append('a');</p>
<p>&nbsp;&nbsp;&nbsp; sb.Append(Char.MinValue);</p>
<p>&nbsp;&nbsp;&nbsp; sb.Append('a');</p>
<p>&nbsp;&nbsp;&nbsp; if (IsPalindrome(sb.ToString(), CultureInfo.CurrentCulture))</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;</p>
<p>&nbsp;&nbsp;&nbsp; return true;</p>
<p>&nbsp;&nbsp;&nbsp; }</p>
<p>/// &lt;summary&gt;</p>
<p>/// A method for testing IsPalindrome, which brings forth the pressing question: who's testing GeneratePalindrome?</p>
<p>/// &lt;/summary&gt;</p>
<p>&nbsp; string GeneratePalindrome()</p>
<p>&nbsp; {</p>
<p>&nbsp;&nbsp;&nbsp; Random random = new Random();</p>
<p>&nbsp;&nbsp;&nbsp; int halfLength = random.Next(80);</p>
<p>&nbsp;&nbsp;&nbsp; char[] buffer = new char[halfLength * 2];</p>
<p>&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; halfLength; i&#43;&#43;)</p>
<p>&nbsp;&nbsp;&nbsp; {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buffer[i] = (char)(random.Next(Char.MinValue, Char.MaxValue));</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buffer[buffer.Length - 1 - i] = buffer[i];</p>
<p>&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; return new string(buffer);</p>
<p>&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp; }</p>
<p>}</p>
<p>posted by pmcculler</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291864020000000</link>
		<pubDate>Fri, 27 Aug 2004 06:53:22 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291864020000000</guid>
		<dc:creator>pmcculler</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>Maurits wrote:</div>
<div>
<blockquote>
<table>
<tbody>
<tr>
<td><img src="/Themes/redesign/images/icon-quote.gif"></td>
<td><strong>Sathyaish Chakravarthy wrote:</strong> <i>
<blockquote>
<table>
<tbody>
<tr>
<td><img src="/Themes/redesign/images/icon-quote.gif"></td>
<td><strong>Maurits wrote:</strong> <i>
<blockquote>
<table>
<tbody>
<tr>
<td><br>
</td>
<td><br>
</td>
</tr>
</tbody>
</table>
</blockquote>
The more I think about it, the more I think that zero-length strings ARE palindromes.&nbsp; This is especially important in recursive algorithms applied to even-length strings.<br>
</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br>
<br>
Could you please elaborate?<br>
</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br>
<br>
OK.&nbsp; One algorithm I've seen is:<br>
Is_Palindrome:<br>
&nbsp; If the string length is 0, return TRUE *<br>
&nbsp; If the string length is 1, return TRUE<br>
&nbsp; If the first character is different than the last character, return FALSE<br>
&nbsp; Otherwise, recursively check the string minus the first and last character<br>
<br>
The *'d line is what I'm referring to.&nbsp; If the TRUE is changed to a FALSE, then every even-length palindrome will incorrectly return FALSE.<br>
<br>
</div>
</blockquote>
<br>
<br>
See my <a href="http://channel9.msdn.com/ShowPost.aspx?PostID=19265#19265">solution</a>, just treat 2-length strings differently, so that it only checks if both characters are the same, and then return true or false in stead of invoking itself with string length
 zero.<p>posted by PeterF</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291893680000000</link>
		<pubDate>Fri, 27 Aug 2004 07:42:48 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632291893680000000</guid>
		<dc:creator>PeterF</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[<br>
bool CheckPalindrome (string CheckString)<br>
{<br>
&nbsp;&nbsp;&nbsp; if (null == CheckString || 0 == CheckString.Length) return false;<br>
&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; CheckString.Length / 2; i&#43;&#43;)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (CheckString[i] != CheckString[CheckString.Length - 1 - i]) return false;<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; return true;<br>
}<br>
<br>
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&nbsp; 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).<br>
<br>
P.S. Thanks for the props, ezu: <a href="http://channel9.msdn.com/ShowPost.aspx?PostID=19369#19369">
http://channel9.msdn.com/ShowPost.aspx?PostID=19369#19369</a><br>
<br>
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?<br>
<br>
P.S.S.S. If you like these sorts of problems, check out <a href="http://www.topcoder.com">http&#58;&#47;&#47;www.topcoder.com</a><br>
<p>posted by xml-blog</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292152500000000</link>
		<pubDate>Fri, 27 Aug 2004 14:54:10 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292152500000000</guid>
		<dc:creator>xml-blog</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>class Processor{<br>
&nbsp;&nbsp;&nbsp;internal static bool isPallindrome(string strValue){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bool result = false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(strValue==null)return result;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[] bits = System.Text.UTF8Encoding.UTF8.GetBytes(strValue);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;short begin = 0, end = (short)bits.Length;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(short x = begin, z = end; x &lt; bits.Length / 2 ; x&#43;&#43;, z--)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result = (bits[x]==bits[z-1]);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return result;<br>
&nbsp;&nbsp;&nbsp;}<br>
};</p>
<p>posted by Garnet</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292159260000000</link>
		<pubDate>Fri, 27 Aug 2004 15:05:26 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292159260000000</guid>
		<dc:creator>Garnet</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>PeterF wrote:</div>
<div>
<blockquote>
<table>
<tbody>
<tr>
<td><img></td>
<td><strong>Maurits wrote:</strong><i>
<blockquote>
<table>
<tbody>
<tr>
<td><img></td>
<td><strong>Sathyaish Chakravarthy wrote:</strong> <i>
<blockquote>
<table>
<tbody>
<tr>
<td><img></td>
<td><strong>Maurits wrote:</strong> <i>
<blockquote>
<table>
<tbody>
<tr>
<td><br>
</td>
<td><br>
</td>
</tr>
</tbody>
</table>
</blockquote>
The more I think about it, the more I think that zero-length strings ARE palindromes.&nbsp; This is especially important in recursive algorithms applied to even-length strings.<br>
</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br>
<br>
Could you please elaborate?<br>
</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br>
<br>
OK.&nbsp; One algorithm I've seen is:<br>
Is_Palindrome:<br>
&nbsp; If the string length is 0, return TRUE *<br>
&nbsp; If the string length is 1, return TRUE<br>
&nbsp; If the first character is different than the last character, return FALSE<br>
&nbsp; Otherwise, recursively check the string minus the first and last character<br>
<br>
The *'d line is what I'm referring to.&nbsp; If the TRUE is changed to a FALSE, then every even-length palindrome will incorrectly return FALSE.<br>
<br>
</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br>
<br>
See my <a target="_blank">solution</a>, just treat 2-length strings differently, so that it only checks if both characters are the same, and then return true or false in stead of invoking itself with string length zero.</div>
</blockquote>
<br>
<br>
There's only one way to settle this - GoogleFight!<br>
<br>
<a href="http://www.googlefight.com/cgi-bin/compare.pl?q1=empty&#43;string&#43;is&#43;a&#43;palindrome&amp;q2=empty&#43;string&#43;is&#43;not&#43;a&#43;palindrome&amp;B1=Make&#43;a&#43;fight%21&amp;compare=1&amp;langue=us">Googlefight</a><br>
<br>
Darn, I lose. <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-9.gif' alt='Crying' /><br>
<br>
<table bgcolor="#ffffff" cellpadding="4" cellspacing="0">
<tbody>
<tr>
<td>
<div><b><a href="http://www.google.com/search?hl=en&amp;ie=ISO-8859-1&amp;q=empty%20string%20is%20a%20palindrome" target="_blank">empty string is a palindrome</a><br>
( 2 640 results)</b></div>
</td>
<td>
<div><b>versus</b></div>
</td>
<td>
<div><b><a href="http://www.google.com/search?hl=en&amp;ie=ISO-8859-1&amp;q=empty%20string%20is%20not%20a%20palindrome" target="_blank">empty string is not a palindrome</a><br>
( 3 990 results)</b></div>
</td>
</tr>
</tbody>
</table>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292279830000000</link>
		<pubDate>Fri, 27 Aug 2004 18:26:23 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292279830000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[But if I use quotes I win:<br>
<table bgcolor="#ffffff" cellpadding="4" cellspacing="0">
<tbody>
<tr>
<td>
<div><b>&quot;empty string is a palindrome&quot;<br>
(38 results)</b></div>
</td>
<td>
<div><b>versus</b></div>
</td>
<td>
<div><b>&quot;empty string is not a palindrome&quot;<br>
(4 results)</b></div>
</td>
</tr>
</tbody>
</table>
<p><br>
<b>The winner is: &nbsp;&nbsp;&nbsp;&quot;empty string is a palindrome&quot;&nbsp;&nbsp;&nbsp;</b> </p>
<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292280700000000</link>
		<pubDate>Fri, 27 Aug 2004 18:27:50 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292280700000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Very Sweet!<br><br>What's going on here?&nbsp; We're on the eve of what will be one of the greatest game launches in history and Tina has been absent for over a month - very distressing!&nbsp; I seriously hope that she will have something to say when Halo launches.<br><br>While I wouldn't mind chilling at EB on midnight, I have work and school to deal with...so I preordered it way back when and it will come to me.&nbsp; EB online FTW!&nbsp; Victory!!!<br><p>posted by USAF1</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292287030000000</link>
		<pubDate>Fri, 27 Aug 2004 18:38:23 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292287030000000</guid>
		<dc:creator>USAF1</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[I Unknown Assembly<br>
<br>
Models &amp; COnceps &amp; Good Languages i need<br>
<br>
i&#43;&#43; i* &lt;#&amp;x&#43;0/&gt; i not need<p>posted by identy</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292330450000000</link>
		<pubDate>Fri, 27 Aug 2004 19:50:45 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292330450000000</guid>
		<dc:creator>identy</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<blockquote>
<div>Maurits wrote:</div>
<div><br>
<b>The winner is: &nbsp;&nbsp;&nbsp;&quot;empty string is a palindrome&quot;&nbsp;&nbsp;&nbsp;</b> </div>
</blockquote>
<br>
<br>
Here is nice problem statement&nbsp;<a href="http://acm.uva.es/problemset/v2/257.html">http://acm.uva.es/problemset/v2/257.html</a>&nbsp;and you
<a href="http://acm.uva.es/problemset/">can submit</a> your solution to be validated (note&nbsp;there used&nbsp;GCC, not MSVC).<br>
<br>
But in reality in real world no one customer will give complete problem statement. You have to collect requerements yourself.<br>
<br>
<br>
<br>
BTW, On 2004/08/24 9:00 (UTC time) there will be <a href="http://online-judge.uva.es/contest/running.html">
real-time online contest</a>.<br>
<br>
Thouse who like problems similar to this one (and a lot of others more hard&nbsp;problems) are invited <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /><p>posted by AT</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292368330000000</link>
		<pubDate>Fri, 27 Aug 2004 20:53:53 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292368330000000</guid>
		<dc:creator>AT</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>How about this:<br>
<br>
private bool IsPalindrome(string phrase)<br>
{<br>
&nbsp; for(int i=0; i&lt;phrase.Length/2; i&#43;&#43;)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; if(!(phrase[i]==phrase[phrase.Length-1-i]))return false;<br>
&nbsp; }<br>
&nbsp; return true;<br>
}</p>
<p>posted by arfnarfsi</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292461660000000</link>
		<pubDate>Fri, 27 Aug 2004 23:29:26 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632292461660000000</guid>
		<dc:creator>arfnarfsi</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[A 17,259-word palindrome is available at:<br>
<a href="http://www.norvig.com/pal2txt.html">http&#58;&#47;&#47;www.norvig.com&#47;pal2txt.html</a><br>
<br>
It's the work of Peter Norvig, Director of Search Quality for Google<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632295753840000000</link>
		<pubDate>Tue, 31 Aug 2004 18:56:24 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632295753840000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[refactored my earlier code:<br>
<br>
static private bool isPalindrome (string stringToTest)<br>
{<br>
&nbsp;char[] stringChars = stringToTest.ToCharArray();<br>
&nbsp;<br>
// format the string<br>
&nbsp;foreach (char character in stringChars)<br>
&nbsp;{<br>
&nbsp;&nbsp; if (char.IsPunctuation(character) || char.IsSeparator(character))<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp; stringToTest = stringToTest.Replace(character.ToString(), &quot;&quot;).ToLower();<br>
&nbsp;&nbsp; }<br>
&nbsp;}<br>
<br>
&nbsp;int halfwayMark = (stringToTest.Length/2);<br>
&nbsp;char[] firstHalf = stringToTest.Substring(0, halfwayMark).ToCharArray();<br>
&nbsp;char[] secondHalf = stringToTest.Substring(halfwayMark).ToCharArray();<br>
<br>
&nbsp;Array.Reverse(secondHalf);<br>
<br>
&nbsp;for (int i=0;i
<p>&nbsp;{<br>
&nbsp;&nbsp;&nbsp; if (firstHalf[i] != secondHalf[i])<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp; return false;<br>
&nbsp;&nbsp; }<br>
&nbsp;}<br>
&nbsp;return true;<br>
}<br>
<br>
performance wise, this is much cheaper than most other solutions presented as it goes char by char.</p>
<p>posted by x.static</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632296197850000000</link>
		<pubDate>Wed, 01 Sep 2004 07:16:25 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632296197850000000</guid>
		<dc:creator>x.static</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[eeesh, it ate my for loop...<br>
<br>
<p>static<b> </b>private<b> </b>bool<b> isPalindrome (</b>string<b> stringToTest)</p>
<p>{</p>
<p></b>char<b>[] stringChars = stringToTest.ToCharArray();</p>
<p></p>
<p></b>// format the string</p>
<b>
<p></b>foreach<b> (</b>char<b> character </b>in<b> stringChars)</p>
<p>{</p>
<p></b>if<b> (</b>char.IsPunctuation(character) || char.IsSeparator(character))</p>
<b>
<p>{</p>
<p>stringToTest = stringToTest.Replace(character.ToString(), </b>&quot;&quot;<b>).ToLower();</p>
<p>}</p>
<p>}</p>
</b><b>
<p></b>int<b> halfwayMark = (stringToTest.Length/2);</p>
<p></b>char<b>[] firstHalf = stringToTest.Substring(0, halfwayMark).ToCharArray();</p>
<p></b>char<b>[] secondHalf = stringToTest.Substring(halfwayMark).ToCharArray();</p>
</b><b>
<p>Array.Reverse(secondHalf);</p>
</b><b>
<p></b>for<b> (</b>int<b> i=0;i&lt;halfwayMark;i&#43;&#43;)</p>
<p>{</p>
<p></b>if<b> (firstHalf[i] != secondHalf[i])</p>
<p>{</p>
<p></b>return<b> </b>false<b>;</p>
<p>}</p>
<p>}</p>
<p></b>return<b> </b>true<b>;</p>
<p>}</p>
</b><p>posted by x.static</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632296199540000000</link>
		<pubDate>Wed, 01 Sep 2004 07:19:14 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632296199540000000</guid>
		<dc:creator>x.static</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>bool IsPalindrome(TCHAR *s) {</p>
<p>&nbsp;&nbsp;&nbsp;TCHAR *e, *p = s;</p>
<p>&nbsp;&nbsp;&nbsp;if (p == 0 || *p == 0) return false;</p>
<p>&nbsp;&nbsp;&nbsp;e = p &#43; _tcslen(p) - 1;</p>
<p>&nbsp;&nbsp;&nbsp;while (*e == *p &amp;&amp; e != p &amp;&amp; e != s) { e--; p&#43;&#43;; }</p>
<p>&nbsp;&nbsp;&nbsp;return e == p || e == s;</p>
<p>}<br>
<br>
</p>
<p>printf(&quot;%s=%d\n&quot;, &quot;ABBA&quot;, IsPalindrome(&quot;ABBA&quot;));<br>
printf(&quot;%s=%d\n&quot;, &quot;ABXBA&quot;, IsPalindrome(&quot;ABXBA&quot;));<br>
<br>
ABBA=1<br>
ABXBA=1</p>
<p>posted by JonasE</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297131380000000</link>
		<pubDate>Thu, 02 Sep 2004 09:12:18 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297131380000000</guid>
		<dc:creator>JonasE</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Channel 9 should have a 'weekly coding challenge'.</p>
<p>posted by ZippyV</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297219630000000</link>
		<pubDate>Thu, 02 Sep 2004 11:39:23 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297219630000000</guid>
		<dc:creator>ZippyV</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>private bool IsPalindrome(string checkString)<br>
{<br>
&nbsp;&nbsp;&nbsp;bool result = true;</p>
<p>&nbsp;&nbsp;&nbsp;if (checkString != null)<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i=0; i&lt;checkString.Length; i&#43;&#43;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (checkString.Substring(i, 1) != checkString.Substring(checkString.Length - (i &#43; 1), 1))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result = false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;return result;<br>
}</p>
<p>posted by jj</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297258160000000</link>
		<pubDate>Thu, 02 Sep 2004 12:43:36 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297258160000000</guid>
		<dc:creator>jj</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>private bool IsPalindrome(string checkString)<br>
{<br>
&nbsp;&nbsp;&nbsp;if ((checkString == null) || (checkString == &quot;&quot;))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>
<br>
&nbsp;&nbsp;&nbsp;bool result = true;<br>
<br>
&nbsp;&nbsp;&nbsp;for (int i=0; i&lt;checkString.Length; i&#43;&#43;)<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (checkString.Substring(i, 1) != checkString.Substring(checkString.Length - (i &#43; 1), 1))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result = false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;return result;<br>
}</p>
<p>posted by jj</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297262270000000</link>
		<pubDate>Thu, 02 Sep 2004 12:50:27 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297262270000000</guid>
		<dc:creator>jj</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Implementing IsPalindrome with a call to _IsPalindrome is not a solution to the problem. Neither are implementations where reverse is used&nbsp;or split-string-in-two-for-comparison.&nbsp;I am talking about&nbsp;the problem those interviewers&nbsp;had (i.e. to find a skilled
 programmer).<br>
<br>
Higher level languages need another problem domain. Here's a problem to a C# developer that should match IsPalindrome in C/C&#43;&#43;.<br>
<br>
- Implement a fund trading system!<br>
<br>
Or this one ... What's the output&nbsp;from this program (copied from Essential .NET):<br>
<br>
public interface ICommon {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void DoIt();</p>
<p>}</p>
<p>&nbsp;</p>
<p>public class Base : ICommon {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void ICommon.DoIt() { Debug.Write (“A”); }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public virtual void DoIt() { Debug.Write (“B”); }</p>
<p>}</p>
<p>&nbsp;</p>
<p>public class Derived : Base, ICommon {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void ICommon.DoIt() { Debug.Write (“C”); }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public new virtual void DoIt() { Debug.Write (“D”); }</p>
<p>}</p>
<p>&nbsp;</p>
<p>public class ReallyDerived : Derived, ICommon {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override void DoIt() { Debug.Write (“E”); }</p>
<p>}</p>
<p>&nbsp;</p>
<p>static void Main() {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReallyDerived r1 = new ReallyDerived();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Derived r2 = r1;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Base r3 = r1;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ICommon r4 = r1;</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r1.DoIt();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r2.DoIt();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r3.DoIt();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r4.DoIt();</p>
<p>}</p>
<p></p>
<p>posted by JonasE</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297312530000000</link>
		<pubDate>Thu, 02 Sep 2004 14:14:13 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297312530000000</guid>
		<dc:creator>JonasE</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>#include &lt;iostream&gt;<br>
#include &lt;string&gt;<br>
#include &lt;algorithm&gt;<br>
using namespace std;</p>
<p>bool IsPalindrome(string sz)<br>
{<br>
&nbsp; string szReverse(sz.length(), ' ');<br>
&nbsp; reverse_copy(sz.begin(), sz.end(), szReverse.begin());<br>
&nbsp; return szReverse == sz;<br>
}</p>
<p>bool IsPalindrome2(string sz)<br>
{<br>
&nbsp; string::iterator forward = sz.begin(), backward = sz.end() - 1;<br>
&nbsp; while( forward&nbsp;&lt; backward &amp;&amp; *forward == *backward ) {<br>
&nbsp;&nbsp;&nbsp; &#43;&#43;forward; --backward;<br>
&nbsp; }<br>
&nbsp; return forward &gt;= backward;<br>
}</p>
<p>template&lt;typename T&gt;<br>
bool IsPalindrome3(T sz)<br>
{<br>
&nbsp; T::iterator forward = sz.begin(), backward = sz.end() - 1;<br>
&nbsp; while( !(forward - 1 == backward || forward == backward) &amp;&amp; *forward == *backward ) {<br>
&nbsp;&nbsp;&nbsp; &#43;&#43;forward; --backward;<br>
&nbsp; }<br>
&nbsp; return (forward - 1 == backward || forward == backward);<br>
}</p>
<p>int main()<br>
{<br>
&nbsp; string sz;<br>
&nbsp; cout &lt;&lt; &quot;Please enter a string:&quot; &lt;&lt; endl;<br>
&nbsp; getline(cin, sz);<br>
&nbsp; if( IsPalindrome2(sz) )<br>
&nbsp;&nbsp;&nbsp; cout &lt;&lt; &quot;It's a palindrome!&quot; &lt;&lt; endl;<br>
&nbsp; else<br>
&nbsp;&nbsp;&nbsp; cout &lt;&lt; &quot;It's not a palindrome!&quot; &lt;&lt; endl;<br>
&nbsp; <br>
&nbsp; return 0;<br>
}<br>
<br>
Three versions in C&#43;&#43;, the first one is the lazyman's version, using std::reverse_copy. The second one is the iterator implementation. And since I figured I was using iterators anyway, so why not make a templated version that works on any standard container
 that defines a begin() and end() that return a bidirectional iterator. That way you can check a std::list for&nbsp;being a palindrome&nbsp;too! ^_^<br>
You could also make a version two template iterator parameters, like many of the &lt;algorithm&gt; functions, that would work on
<strong>any</strong> bidirectional iterator, including pointers.</p>
<p>posted by Sven Groot</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297599640000000</link>
		<pubDate>Thu, 02 Sep 2004 22:12:44 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632297599640000000</guid>
		<dc:creator>Sven Groot</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[If I had been asked this question I would be all smiles. Throughout college, the excercise we were asked to do with all languages except COBOL was to write a function that determined whether or not a word was a palindrome.
<br>
<br>
This was a great video, and it excites me to see what MS Campus is like.<p>posted by fabulous</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632303486730000000</link>
		<pubDate>Thu, 09 Sep 2004 17:44:33 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632303486730000000</guid>
		<dc:creator>fabulous</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Oops, here is a quick implementation in VB.NET. I am not addressing the spaces or case sensitivity. This is in a class with Option Compare Text turned on. For those who don't speak VB, Option Compare&nbsp;Text will allow you to evaluate true and TrUe as equal
 because it compares how the string is read and not the individual characters where a != A.<br>
<br>
<p>Private Function IsPalindrome(ByVal inWord As String) As Boolean<br>
&nbsp;&nbsp;&nbsp;Dim max As Integer = inWord.Length - 1<br>
&nbsp;&nbsp;&nbsp;For i As Integer = 0 To max \ 2<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If Not inWord.Substring(i, 1) = inWord.Substring(max - i, 1) Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Return False<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>
&nbsp;&nbsp;&nbsp;Next<br>
&nbsp;&nbsp;&nbsp;Return True<br>
End Function</p>
<p>posted by fabulous</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632303491420000000</link>
		<pubDate>Thu, 09 Sep 2004 17:52:22 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632303491420000000</guid>
		<dc:creator>fabulous</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Here is a recursive version of palindrome checker<br>
<br>
public bool IsPalindrome(string s)<br>
{<br>
&nbsp;&nbsp;&nbsp;if(s==null) return false;&nbsp;<br>
&nbsp;&nbsp;&nbsp;s = s.Replace(&quot; &quot;, &quot;&quot;);<br>
&nbsp;&nbsp; if(s.Length == 0) return false;<br>
&nbsp;&nbsp;&nbsp;return IsPalindrome(s, 0, s.length);<br>
}<br>
<br>
private&nbsp;bool IsPalindrome(String s, int first, int last)&nbsp;<br>
{<br>
&nbsp;&nbsp;&nbsp;if(first &gt;= (s.Length / 2)) return true;&nbsp;<br>
&nbsp;&nbsp;&nbsp;if ( s[first] == s[last])<br>
&nbsp;&nbsp;&nbsp;&nbsp;return IsPalindrome(s, &#43;&#43;first, --last);<br>
&nbsp;&nbsp;&nbsp;else<br>
&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>
}<br>
<br>
<p>posted by rpg</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632303524390000000</link>
		<pubDate>Thu, 09 Sep 2004 18:47:19 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632303524390000000</guid>
		<dc:creator>rpg</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[ZippyV, that would an excellent idea.<br>
<p>posted by sc00ter</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632303617060000000</link>
		<pubDate>Thu, 09 Sep 2004 21:21:46 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632303617060000000</guid>
		<dc:creator>sc00ter</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Had to throw my 2 cents in. A lot of you have great ideas about how to reverse and compare a string but I haven't seen anyone really interrogate the problem top down correctly. That goes for the guy in the video who posed it.
<br>
<br>
A palindrome is a word, phrase or verse that is&nbsp;READ the same backward as forward. I believe this also implies&nbsp;Means&nbsp;the same. Just the fact that it must be a word, phrase or verse means aBBa is not a Palindrome. (In English anyway)&nbsp; Neither is 'm'. Neither
 could a book (ie War and Peace <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' />). So the guy in the video was incorrect in answering yes to that question. (Needs to sharpen&nbsp;HIS information gathering skills). Since reading a word, phrase or verse implies it is in a consistent language (Joyce's Ulysses
 aside)&nbsp;characters inconsistent with&nbsp;that language make testing impossible. An accent grave or aigu used in a&nbsp;standard English sentence would disqualify it&nbsp;and should raise an INVALID_CHARACTER_ERROR.
<br>
Punctuation such as commas, colons, dashes etc.. are in another layer of sentence structure addressing interpretation. They are irrelevant to determining whether a word, phrase or verse is a palindrome.<br>
&nbsp;<br>
So the rules for reversing a string and comparing it are much different from determining if a word, phrase or verse is a palindrome.
<br>
<br>
Some of you hinted at this when you suggested puncutation and spaces should be stripped before making the comparison. I suppose to make the function&nbsp;generic one would have to add an additional parameter of dictionary. This would also help take care of Unicode
 issues. <br>
<br>
If we consider the poser of the original task as playing the role of user I think we can glean something from the excercise other than 100 routines to&nbsp;find out if a string is layed out the same backwards as forwards. It is something that I think we can all
 relate to in our efforts to&nbsp;define a problem as communicated to us&nbsp;by our users. When he said 'Palindrome' and&nbsp;proceeded to outline the rules, at some point we would think &quot;I get it. He means reverse the string and see if it is the same. He's using Palindrome
 to let us know that he&nbsp;knows (or thinks he knows) the word and&nbsp;therefore is an intelligent and exciting individual.&quot; We would then go write the String_Compare_Reversal method according to his rules and he would be happy.<br>
<br>
<br>
<br>
</p>
<p>posted by CatsCradle</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632303757410000000</link>
		<pubDate>Fri, 10 Sep 2004 01:15:41 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632303757410000000</guid>
		<dc:creator>CatsCradle</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[That was an interesting clip <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br>
<br>
The result I would have come up with would have been something similar to:<br>
<br>
<p>bool IsPanlindrome( TCHAR *pszString )<br>
{<br>
&nbsp;&nbsp;&nbsp;if ( NULL == pszString )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>
<br>
&nbsp;&nbsp;&nbsp;const int length = lstrlen( pszString );<br>
&nbsp;&nbsp;&nbsp;const int repeat = length / 2;<br>
<br>
&nbsp;&nbsp;&nbsp;for ( int loop = 0; loop &lt; repeat; &#43;&#43;loop )<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( pszString[ loop ] != pszString[ length - 1 - loop ] )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>
&nbsp;&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;&nbsp;return ( 0 != length );<br>
}<br>
<br>
I say similar, because I would probably have been very nervous so it may not have been exactly the same. I also think I wouldn't have written as much pseudo code as in the video, as the simplicity of the question coupled with my nervousness may have had me
 thinking 'he just wants me to write the code'.<br>
<br>
I would have pointed out I was dividing the length by two because the integer arithmetic would simply discard the central character for odd length strings.<br>
<br>
n!</p>
<p>posted by nfactorial_</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632305400320000000</link>
		<pubDate>Sat, 11 Sep 2004 22:53:52 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632305400320000000</guid>
		<dc:creator>nfactorial_</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p></p>
<blockquote>
<div>ZippyV wrote:</div>
<div>
<p></p>
<p>Channel 9 should have a 'weekly coding challenge'.</p>
<p></p>
</div>
</blockquote>
<br>
<br>
10 out 10 for a good idea!!!!
<p></p>
<p>posted by CaptainOblivious</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632313385330000000</link>
		<pubDate>Tue, 21 Sep 2004 04:42:13 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632313385330000000</guid>
		<dc:creator>CaptainOblivious</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Just stumbled across this, I'm not sure though if your question was answered, but here's my widow's mite. Yes a char by char check is more efficient.
<br>
<br>
A level lower and a look at the asm/binary generated by your compiler would reveal the external calls made using the second option. Now realize that every single func call would force your processor to save its registers to mem and eventually restore them as
 well as set-up stack frames and a return address. <br>
<br>
With the first option you would likely find a simple reg/reg comparison and jump. Progression thru the arrays would likely be accomplished thru pointer arith.<br>
<br>
Compilers are pretty smart but relatively unnecessary clutter fools them. More elegant with func calls but you'll take a processing hit.<br>
<br>
<p>posted by mochafella</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632313546120000000</link>
		<pubDate>Tue, 21 Sep 2004 09:10:12 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632313546120000000</guid>
		<dc:creator>mochafella</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[that was for &quot;TimP&quot; by the way.<br>
<p>posted by mochafella</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632313547540000000</link>
		<pubDate>Tue, 21 Sep 2004 09:12:34 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632313547540000000</guid>
		<dc:creator>mochafella</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[I'd liek to try my simple C&#43;&#43;:<br>
<br>
bool isPalen(const string &amp; s)<br>
{<br>
&nbsp;&nbsp; int len = s.length();<br>
&nbsp;&nbsp; if(len &lt;= 0)&nbsp; // we can also add more string checking here<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cerr &lt;&lt; &quot;empty input&quot; &lt;&lt; endl;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; for(int i = 0; i &lt; len / 2; &#43;&#43;i)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; s[i] &lt;&lt; endl;&nbsp; // for debugging<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(s[i] != s[len - i - 1])<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; return true;<br>
}<br>
<br>
I'm a new graduate and I wish some engineer in Microsoft liked to interview me.<br>
<p>posted by hong</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632319432050000000</link>
		<pubDate>Tue, 28 Sep 2004 04:40:05 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632319432050000000</guid>
		<dc:creator>hong</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Just wanted to recomend this book, 4 stars rating based on 114 reviews<strong><br>
<br>
Introduction to Algorithms, Second Edition<br>
ISBN 0-262-03293-7<br>
<br>
</strong><a href="http://www.amazon.com/exec/obidos/tg/detail/-/0262032937">http://www.amazon.com/exec/obidos/tg/detail/-/0262032937</a></p>
Preface
<p>This book provides a comprehensive introduction to the modern study of computer algorithms. It presents many algorithms and covers them in considerable depth, yet makes their design and analysis accessible to all levels of readers. We have tried to keep
 explanations elementary without sacrificing depth of coverage or mathematical rigor.&nbsp; Each chapter presents an algorithm, a design technique, an application area, or a related topic.</p>
<p>Algorithms are described in English and in a “pseudocode” designed to be readable by anyone who has done a little programming. The book contains over 230 figures illustrating how the algorithms work. Since we emphasize
<i>efficiency </i>as a design criterion, we include careful analyses of the running times of all our algorithms.</p>
<p>The text is intended primarily for use in undergraduate or graduate courses in algorithms or data structures. Because it discusses engineering issues in algorithm design, as well as mathematical aspects, it is equally well suited for self-study by technical
 professionals.&nbsp; In this, the second edition, we have updated the entire book. The changes range from the addition of new chapters to the rewriting of individual sentences.</p>
<em>To the teacher</em>
<p>This book is designed to be both versatile and complete. You will find it useful for a variety of courses, from an undergraduate course in data structures up through a graduate course in algorithms. Because we have provided considerably more material than
 can fit in a typicalone-term course, you should think of the book as a “buffet” or “smorgasbord” from which you can pick and choose the material that best supports the course you wish to teach. You should find it easy to organize your course around just the
 chapters you need. We have made chapters relatively self-contained, so that you need not worry about an unexpected and unnecessary dependence of one chapter on another. Each chapter presents the easier material first and the more difficult material later,
 with section boundaries marking natural stopping points. In an undergraduate course, you might use only the earlier sections from a chapter; in a graduate course, you might cover the entire chapter. We have included over 920 exercises and over 140 problems.
 Each section ends with exercises, and each chapter ends with problems. The exercises are generally short questions that test basic mastery of the material. Some are simple self-check thought exercises, whereas others are more substantial and are suitable as
 assigned homework. The problems are moreelaborate case studies that often introduce new material; they typically consist of several questions that lead the student through the steps required to arrive at a solution.</p>
<p>We have starred (⋆) the sections and exercises that are more suitable for graduate students than for undergraduates. A starred section is not necessarily more difficult than an unstarred one, but it may require an understanding of more advanced mathematics.
 Likewise, starred exercises may require an advanced background or more than average creativity.</p>
<em>To the student</em>
<p>We hope that this textbook provides you with an enjoyable introduction to the field of algorithms. We have attempted to make every algorithm accessible and interesting. To help you when you encounter unfamiliar or difficult algorithms, we describe each one
 in a step-bystep manner. We also provide careful explanations of the mathematics needed to understand the analysis of the algorithms. If you already have some familiarity with a topic, you will find the chapters organized so that you can skim introductory
 sections and proceed quickly to the more advanced material.</p>
<p>This is a large book, and your class will probably cover only a portion of its material. We have tried, however, to make this a book that will be useful to you now as a course textbook and also later in your career as a mathematical desk reference or an
 engineering handbook. What are the prerequisites for reading this book?</p>
<p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; You should have some programming experience. In particular, you should understand recursive procedures and simple data structures such as arrays and linked lists.</p>
<p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; You should have some facility with proofs by mathematical induction. A few portions of the book rely on some knowledge of elementary calculus. Beyond that, Parts I and VIII of this book teach you all the mathematical techniques you will need.</p>
<em>To the professional</em>
<p>The wide range of topics in this book makes it an excellent handbook on algorithms. Because each chapter is relatively self-contained, you can focus in on the topics that most interest you. Most of the algorithms we discuss have great practical utility.
 We therefore address implementation concerns and other engineering issues. We often provide practical alternatives to the few algorithms that are primarily of theoretical interest.</p>
<p>If you wish to implement any of the algorithms, you will find the translation of our pseudocode into your favorite programming language a fairly straightforward task. The pseudocode is designed to present each algorithm clearly and succinctly. Consequently,
 we do not address error-handling and other software-engineering issues that require specific assumptions about your programming environment. We attempt to present each algorithm simply and directly without allowing the idiosyncrasies of a particular programming
 language to obscure its essence.</p>
<p>&nbsp;</p>
<p>posted by prog_dotnet</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632335761990000000</link>
		<pubDate>Sun, 17 Oct 2004 02:16:39 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632335761990000000</guid>
		<dc:creator>prog_dotnet</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Start:<br>
jmp Go<br>
string db 'AXaXA'<br>
<br>
Palindrome proc near<br>
&nbsp;mov al,0<br>
&nbsp;test ecx,ecx<br>
&nbsp;jz ext<br>
&nbsp;pusha<br>
&nbsp;mov ebx,0<br>
&nbsp;mov edx,edi<br>
&nbsp;add edx,ecx<br>
&nbsp;shr ecx,1<br>
&nbsp;lop:<br>
&nbsp;&nbsp;mov ah,[edi&#43;ebx]<br>
&nbsp;&nbsp;inc ebx<br>
&nbsp;&nbsp;cmp ah,[edx-ebx]<br>
&nbsp;&nbsp;jne nope<br>
&nbsp;dec ecx<br>
&nbsp;jnz lop<br>
&nbsp;inc al<br>
&nbsp;nope:<br>
&nbsp;popa<br>
&nbsp;ext:<br>
&nbsp;retn<br>
Palindrome endp
<pre></pre>
<pre>Go:<br>lea edi,[string]<br>mov ecx,5&nbsp;;length<br>call Palindrome<br>;al=1 == true</pre>
<p>posted by mikosoft</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632337250550000000</link>
		<pubDate>Mon, 18 Oct 2004 19:37:35 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632337250550000000</guid>
		<dc:creator>mikosoft</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[It is cool video...<br>
<br>
But I am very sad because this video was release&nbsp;at 10/18/2004 3:36:34 PM in home Channel 9, but first post was submitted at Tuesday, Aug 24, 2004 3:59 PM <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-6.gif' alt='Sad' /><br>
<br>
I wanna see it, in first day. How..??? Where..????<br>
<br>
I could&nbsp;sent my code for palindrome function <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-6.gif' alt='Sad' /><br>
<br>
Thanks you.<p>posted by guydotnetxmlwebservices</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632339662140000000</link>
		<pubDate>Thu, 21 Oct 2004 14:36:54 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632339662140000000</guid>
		<dc:creator>guydotnetxmlwebservices</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[To watch the videos as soon as they are put up, either visit the home page every day, or get an RSS News Aggregator and subscribe to the Channel 9 Video RSS feed at
<a href="http://channel9.msdn.com/rss.aspx?ForumID=14&amp;Mode=0">http://channel9.msdn.com/rss.aspx?ForumID=14&amp;Mode=0</a><p>posted by The Channel 9 Team</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632339849010000000</link>
		<pubDate>Thu, 21 Oct 2004 19:48:21 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632339849010000000</guid>
		<dc:creator>The Channel 9 Team</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>bool IsPalindrome(string str){</p>
<p>&nbsp;&nbsp;&nbsp;if(str.length()==0)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;</p>
<p>&nbsp;&nbsp;&nbsp;else if(str.length()&lt;=2)</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return str[0]==str[str.length()-1];</p>
<p>&nbsp;&nbsp;&nbsp;else{</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(str[0]==str[str.length()-1])</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return IsPalindrome(str.substr(1,str.length()-2));</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;</p>
<p>&nbsp;&nbsp;&nbsp;}<br>
<br>
}</p>
<p>posted by Rtugok</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632344206960000000</link>
		<pubDate>Tue, 26 Oct 2004 20:51:36 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632344206960000000</guid>
		<dc:creator>Rtugok</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Function isPalendrome(ByVal a As String) As Boolean</p>
<p>If a.Length &lt; 2 Then Return True</p>
<p>If a.Chars(0) = a.Chars(a.Length - 1) Then</p>
<p>a = a.Remove(a.Length - 1, 1)</p>
<p>If a.Length &gt; 0 Then a = a.Remove(0, 1)</p>
<p>Return isPalendrome(a)</p>
<p>End If</p>
<p>Return False</p>
<p>End Function</p>
<p>posted by Guster_Q</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632472191950000000</link>
		<pubDate>Wed, 23 Mar 2005 23:59:55 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632472191950000000</guid>
		<dc:creator>Guster_Q</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Boy, oh boy, the presentors would never get a job in our company: poor reasoning process, bad solution.<br>
<br>
This problem is so simple that the whole solution is just one line of generic code (also with guaranteed complexity):<br>
<br>
template&lt;typename StringType&gt;<br>
inline bool is_palindrom(const StringType&amp; str)<br>
{&nbsp;<br>
&nbsp;&nbsp;&nbsp;return std::equal(str.begin(), str.begin() &#43; str.size()/2, str.rend());<br>
}<br>
<br>
now you can instantiate the function on std::string, std::wstring, std::vector&lt;char&gt;, or whatever container is appropriate for your application, which has random access iterators. And if you need to&nbsp;make it case-insensitive, just&nbsp;add a corresponding binary
 predicate for std::equal, which is another one&nbsp;line of code for English, or can be non-trivial for other languages. You can even test for palindrom objects that are not strings, as long as they contain equality comparable types.<br>
<p>posted by homerjay</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632473904800000000</link>
		<pubDate>Fri, 25 Mar 2005 23:34:40 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632473904800000000</guid>
		<dc:creator>homerjay</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Is it just me, or is the code in the video broken?&nbsp;The &quot;=&gt;&quot; in the &quot;while&quot; condition ought to be &quot;&lt;&quot;...<br>
<br>
What do you think?</p>
<p>posted by peterpeter</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632476258010000000</link>
		<pubDate>Mon, 28 Mar 2005 16:56:41 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632476258010000000</guid>
		<dc:creator>peterpeter</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[bool IsPalindrome(TCHAR* tzString)<br>
{<br>
<br>
&nbsp;&nbsp;&nbsp;// The odds of a string being Palindrome&nbsp;<br>
&nbsp;&nbsp;&nbsp;//&nbsp;is less&nbsp;than one in a million so this function<br>
&nbsp;&nbsp;&nbsp;// returns false, just being safe.<br>
<br>
&nbsp;&nbsp;&nbsp;// TODO: add code here to improve this function.<br>
<br>
&nbsp;&nbsp;&nbsp;return false;<br>
<br>
<br>
}<p>posted by Jos104</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632482440070000000</link>
		<pubDate>Mon, 04 Apr 2005 20:40:07 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632482440070000000</guid>
		<dc:creator>Jos104</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p><br>
<br>
'puncuation and case and space sensitive<br>
Function ispal(ByVal str As String) As Boolean<br>
&nbsp;&nbsp;&nbsp;Dim chars As Char() = str.ToCharArray()<br>
&nbsp;&nbsp;&nbsp;Array.Reverse(chars)<br>
&nbsp;&nbsp;&nbsp;If TextBox1.Text = chars Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Return True<br>
&nbsp;&nbsp;&nbsp;Else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Return False<br>
&nbsp;&nbsp;&nbsp;End If<br>
End Function<br>
<br>
</p>
<p>posted by HippieGeek</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632482489150000000</link>
		<pubDate>Mon, 04 Apr 2005 22:01:55 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632482489150000000</guid>
		<dc:creator>HippieGeek</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>namespace Infocus<br>
{<br>
&nbsp;&nbsp;&nbsp;using System;<br>
<br>
&nbsp;&nbsp;&nbsp;public sealed class Util<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private Util(){}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;summary&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// Verifies the input text is a palindrome.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;/summary&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;param name=&quot;input&quot;&gt;The text to be&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;verified.&lt;/param&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;param name=&quot;ignoreWhitepspace&quot;&gt;Option set to true to ignore whitespace.&lt;/param&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;param name=&quot;caseSensitive&quot;&gt;Option that toggles case-sensitive.&lt;/param&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;param name=&quot;alphaOnly&quot;&gt;Option that verifies only alpha-numeric characters exist.&lt;/param&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static void VerifyPalindrome(string input, bool ignoreWhitespace, bool caseSensitive, bool alphaOnly)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
#if DEBUG<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// verify input is not null<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// NOTE: we could simply rely on Replace() below to throw this exception, hence DEBUG<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (input == null)&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new NullReferenceException(&quot;Input cannot be null.&quot;);<br>
#endif<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// strip whitespace<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (ignoreWhitespace)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input = System.Text.RegularExpressions.Regex.Replace(input, @&quot;\s&quot;, &quot;&quot;);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;verify alphanumeric<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (alphaOnly &amp;&amp; System.Text.RegularExpressions.Regex.IsMatch(input, @&quot;\W&quot;))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new ApplicationException(&quot;Input contained non-alphanumeric characters.&quot;);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// lowercase input<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!caseSensitive)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input = input.ToLower();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// verify input length is valid for a palindrome<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (input.Length &lt; 2)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new ApplicationException(&quot;Length of input must be greater than 1.&quot;);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int forwardIndexer = 0, reverseIndexer = input.Length-1;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while ((forwardIndexer &lt;= reverseIndexer) &amp;&amp; (input[forwardIndexer] == input[reverseIndexer]))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;forwardIndexer&#43;&#43;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reverseIndexer--;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (forwardIndexer&nbsp;&lt;= reverseIndexer)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new ApplicationException(&quot;Not a valid Palindrome.&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;summary&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// Performs a case insensitive, non-whitespace intensive palindrome verification on the input string.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;/summary&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;returns&gt;true if input is a palindrome&lt;/returns&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static bool IsPalindrome(string input)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VerifyPalindrome(input, true, false, false);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catch (ApplicationException appex)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;}<br>
}<br>
<br>
<br>
I prefer that exceptions be leveraged especially for internal code. Optimization based on failure-rates aside, I think it's more elegant to say in-code:<br>
<br>
string&nbsp;input = &quot;dood&quot;; <br>
VerifyPalindrome(input);<br>
<br>
and then fail back to the caller if he supplied us with invalid input. No need to continually re-invent error checks because of booleans along the stack.<br>
<br>
Of course, 1 or two more overloads wouldn't hurt.<br>
<br>
I didn't read through ALL posts made by everyone. If it looks like I copied your code, sorry, just know I didn't get past the t-sql post on the first page before realizing I thought the code should be done differently. This took me 9 minutes. I didn't test
 it (whiteboards don't have a debugger at Microsoft, do they?)<br>
</p>
<p>posted by SEWilson</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632482639110000000</link>
		<pubDate>Tue, 05 Apr 2005 02:11:51 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632482639110000000</guid>
		<dc:creator>SEWilson</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[To be pedantic your alphaOnly parameter also allows underscores as well as alphabetic and numeric characters.<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632500684850000000</link>
		<pubDate>Mon, 25 Apr 2005 23:28:05 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632500684850000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Here is an internationally savvy solution that works with Whidbey Beta 2....<br>
<br>
<p>using System;<br>
using System.Text;<br>
using System.Globalization;</p>
<p>bool IsPalindrome(string st) {<br>
&nbsp;&nbsp;StringInfo si = new StringInfo(st);<br>
&nbsp; int count = si.LengthInTextElements;<br>
<br>
&nbsp; if (count == 0) return false;&nbsp;<br>
<br>
&nbsp; for (int i = 0; i &lt; ((count % 2 != 0) ? count - 1 : count) / 2; i&#43;&#43;) {<br>
&nbsp;&nbsp;&nbsp; string st1 = si.SubstringByTextElements(i, 1);<br>
&nbsp;&nbsp;&nbsp; string st2 = si.SubstringByTextElements(count - i - 1, 1);<br>
<br>
&nbsp;&nbsp;&nbsp; if (CultureInfo.CurrentCulture.CompareInfo.Compare(st1, st2) != 0) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return(false);<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp; }<br>
<br>
&nbsp;&nbsp;return (true);<br>
}</p>
<p>posted by michkap</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632502994390000000</link>
		<pubDate>Thu, 28 Apr 2005 15:37:19 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632502994390000000</guid>
		<dc:creator>michkap</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Locale-dependency!&nbsp; The missing piece!&nbsp; Sweet!<br>
Throw in a couple ToLower() and IsAlpha() calls and we finally have a C-like solution that can handle the test case
<a href="http://channel9.msdn.com/ShowPost.aspx?PostID=19194#19194">I proposed</a> at the very beginning of this thread:<br>
<br>
A man, a plan, a canal - Panamá! (note the accent)<br>
<br>
EDIT: Hmm, the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationcompareoptionsclasstopic.asp">
CompareOptions</a> enum has things like IgnoreCase, IgnoreKanaType (Japanese has two alphabets), IgnoreNonSpace (accents etc.), IgnoreSymbols (spaces are symbols) - tailor-made!&nbsp; Might even be able to write one-line IsPalindrome with this kind of power.<br>
<br>
EDIT2:<br>
Not quite one-line, but nice:<br>
<br>
<pre class="brush: text">
using System;
using System.Text;
using System.Globalization;

bool IsPalindrome(string s)
{   char[] cs = s.ToCharArray();
    Array.Reverse(cs);
    string r = new string(cs);

    CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;
    CompareOptions co =
        CompareOptions.IgnoreCase |
        CompareOptions.IgnoreKanaType |
        CompareOptions.IgnoreNonSpace |
        CompareOptions.IgnoreSymbols |
        CompareOptions.IgnoreWidth;

    return (ci.Compare(s, r, co) == 0);
}
</pre>
<br>
<br>
Note IsPalindrome(&quot;A man, a plan, a canal - Panamá!&quot;) == true<br>
Also note IsPalindrome(&quot;&quot;) == true - a feature<br>
<br>
Posted <a href="http://channel9.msdn.com/ShowPost.aspx?PostID=63167">driver app</a> in Sandbox<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632503077540000000</link>
		<pubDate>Thu, 28 Apr 2005 17:55:54 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632503077540000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Note that this will fail for all types of combining characters -- thus the stringinfo stuff being needed? <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /></p>
<p>posted by michkap</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632503151820000000</link>
		<pubDate>Thu, 28 Apr 2005 19:59:42 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632503151820000000</guid>
		<dc:creator>michkap</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Ah... due to the ArrayReverse... I see... working on a fix<br>
<br>
EDIT: here's the fix (don't have Whidbey beta 2, sorry)<br>
<br>
<pre class="brush: text">
string StringReverse(string s)
{    TextElementEnumerator e = StringInfo.GetTextElementEnumerator(s);
    string r = &quot;&quot;;

    while (e.MoveNext())
    {    r = e.GetTextElement() &#43; r;
    }

    return r;
}

bool IsPalindrome(string s)
{   string r = StringReverse(s);

    CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;
    CompareOptions co =
        CompareOptions.IgnoreCase |
        CompareOptions.IgnoreKanaType |
        CompareOptions.IgnoreNonSpace |
        CompareOptions.IgnoreSymbols |
        CompareOptions.IgnoreWidth;

    return (ci.Compare(s, r, co) == 0);
}
</pre>
<br>
<br>
I'm trying to do an iterative version too - where instead of copy/reverse, you put a finger on the beginning and the end and compare relevant TextElements until you either find a mismatch (return false) or your fingers meet (return true)<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632503200410000000</link>
		<pubDate>Thu, 28 Apr 2005 21:20:41 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632503200410000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[And here's the iterative version:<br>
<pre class="brush: text">
bool IsPalindrome(string s)
{    CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;
    CompareOptions co =
        CompareOptions.IgnoreCase |
        CompareOptions.IgnoreKanaType |
        CompareOptions.IgnoreNonSpace |
        CompareOptions.IgnoreSymbols |
        CompareOptions.IgnoreWidth;

    int i = 0;
    TextElementEnumerator e = StringInfo.GetTextElementEnumerator(s);
            
    while (e.MoveNext())
    {    i&#43;&#43;; // just counting, that's all
    }

    String[] ts = new String[ i ];

    e.Reset();
    i = 0;
    while (e.MoveNext())
    {    ts[ i ] = e.GetTextElement();
        i&#43;&#43;;
    }

    // phew!  Now ts[ i ] is an array of textelements
    // place finger A on the beginning of the string
    // place finger B on the end of the string
    // move fingers toward the middle a step at a time
    // until you get to a mismatch or your fingers meet
    int a = 0;
    int b = ts.Length - 1;
    while (a &lt; b)
    {    // move A forward until you find an interesting element
        while (a &lt; b &amp;&amp; ci.Compare(ts[ a ], &quot;&quot;, co) == 0)
        {    a&#43;&#43;;
        }

        // move B backward until you find an interesting element
        while (a &lt; b &amp;&amp; ci.Compare(ts[ b ], &quot;&quot;, co) == 0)
        {    b--;
        }

        if (a &lt; b)
        {    // compare the two elements
            // if they're the same, continue...
            if (ci.Compare(ts[ a ], ts[ b ], co) == 0)
            {    a&#43;&#43;; b--;
            }
            else // they're different - NOT a palindrome
            {    return false;
            }
        }
    }

    return true;
}
</pre>
<br>
<br>
Updated Sandbox project<br>
Instead of hardcoding the CompareOptions I created checkboxes for all the Ignore... options.&nbsp; Default is to ignore everything.<br>
<p>posted by Maurits</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632503221050000000</link>
		<pubDate>Thu, 28 Apr 2005 21:55:05 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632503221050000000</guid>
		<dc:creator>Maurits</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Why no one sees the obvious solution using regular<br>
C&#43;&#43; standard library facility:<br>
<br>
bool is_palindrome(const string&amp; s) {<br>
&nbsp;&nbsp;&nbsp;return equal(s.begin(), s.end(), s.rbegin());<br>
}<br>
<br>
<br>
The equal funcition assumes that the second sequence is the same size as the first, so it does not need<br>
and ending iterator.<br>
<br>
<br>
Stefan<p>posted by fxbrain</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632524324100000000</link>
		<pubDate>Mon, 23 May 2005 08:06:50 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632524324100000000</guid>
		<dc:creator>fxbrain</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Not very efficient, and not even a MS product, but here is my interpretation.&nbsp; I'm not horribly efficient, but oh well.<br>
<br>
......<br>
<br>
type<br>
&nbsp; TPalindromeResult = (prTrue, prFalse, prLengthMismatch, prException);<br>
<br>
......<br>
<br>
procedure TForm1.Button1Click(Sender: TObject);<br>
begin<br>
&nbsp; Case IsPalindrome(edit1.Text, edit2.Text) of<br>
&nbsp;&nbsp;&nbsp; prTrue:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MessageDlg('You the man',mtInformation,[mbOk],0);<br>
&nbsp;&nbsp;&nbsp; prFalse:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MessageDlg('You not the man', mtInformation, [mbOk],0);<br>
&nbsp;&nbsp;&nbsp; prLengthMismatch:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MessageDlg('Can''t compare, length mismatch', mtInformation, [mbOk],0);<br>
&nbsp; End;<br>
end;<br>
<br>
......<br>
<br>
function TForm1.IsPalindrome(Str1, Str2: String): TPalindromeResult;<br>
Var<br>
&nbsp; WorkStr : String;<br>
&nbsp; X : Integer;<br>
begin<br>
&nbsp; Try<br>
&nbsp;&nbsp;&nbsp; Try<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Perform basic checks before iteration.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (Length(Str1) &lt;&gt; Length(Str2)) Then Begin<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Result := prLengthMismatch;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For X := 1 to Length(Str1) do<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Insert(Copy(Str2,X,1),WorkStr,0);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (WorkStr = Str1) Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Result := prTrue<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Result := prFalse;</p>
<p>&nbsp;&nbsp;&nbsp; Except<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; On Exception do Result := prException;</p>
<p>&nbsp;&nbsp;&nbsp; End;<br>
&nbsp; Finally<br>
&nbsp;&nbsp;&nbsp; //Perform any necessary cleanup<br>
&nbsp; End;<br>
</p>
<p>posted by RuneSpyder</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632584764580000000</link>
		<pubDate>Mon, 01 Aug 2005 07:00:58 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632584764580000000</guid>
		<dc:creator>RuneSpyder</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[TimP, yours is the best. You make use of the best performing C# implementation by using the native methods in the .net framework and the least lines of code. Just MHO Cheers, Kosher MCSD/MCAD .net<p>posted by Kosher</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632586084870000000</link>
		<pubDate>Tue, 02 Aug 2005 19:41:27 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632586084870000000</guid>
		<dc:creator>Kosher</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Here's what I came up with in a few minutes. It should run in linear time and in-place. Not sure if it will work with TCHARs yet, so I'll give that a shot in a few minutes.<br>
<br>
<pre class="brush: cpp">
bool isAlphaNumeric(char c)
{
    if(iswalpha(c) || iswdigit(c)) return true;
    return false;    
}

bool isPalindrome(char *str)
{
    if(*str == '\0')
    {
        return false;    
    }
    int len = strlen(str);
    if(len &lt;= 1) return true; // 0- or 1-length strings are simplest palindromes
    
    char *start = str;
    char *end = start &#43; strlen(str) - 1;
    
    while(start &lt; end)
    {
        // if start not a char, increment start and continue
        if(!isAlphaNumeric(*start))
        {
            *start&#43;&#43;;
            continue;    
        }
        // if end not a char, decrement end and continue
        if(!isAlphaNumeric(*end))
        {
            *end--;
            continue;    
        }
        // if two characters are not equal, return false
        if(towlower(*start) != towlower(*end)) return false;
        // otherwise start&#43;&#43;, end--
        *start&#43;&#43;;
        *end--;        
    }
    return true;
}
</pre>
<br>
<br>
Edit: Yup, substituting TCHAR for char works just fine. And just for the hell of it, here's strrev (or revstr, to avoid name conflicts)<br>
<br>
<pre class="brush: cpp">
void revstr(TCHAR *str)
{
    if(*str == '\0')
    {
        return;    
    }
    
    TCHAR *start = str;
    TCHAR *end = start &#43; strlen(str) - 1;
    
    while(start &lt; end)
    {
        *start ^= *end;
        *end ^= *start;
        *start ^= *end;
        *start&#43;&#43;;
        *end--;
        // could also use *start ^= *end ^= *start&#43;&#43; ^= *end-- if you want to get fancy
    }    
}
</pre>
<br>
<p>posted by DoggettCK</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632591974580000000</link>
		<pubDate>Tue, 09 Aug 2005 15:17:38 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632591974580000000</guid>
		<dc:creator>DoggettCK</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Ike-it's Ritz!&nbsp; Where you been?&nbsp; I was talking to JJ last night, and he said MJK had come across this video.&nbsp; Nice work!&nbsp;
<br>
-LIZ<p>posted by ritzbit</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632639484860000000</link>
		<pubDate>Mon, 03 Oct 2005 15:01:26 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632639484860000000</guid>
		<dc:creator>ritzbit</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[A bit too late (like a year or so, but just stumbled on this video preparing for my own interview...). Anyway here is my 2 cents in Java (handles case, punctuation, spaces by ignoring them). Tried to compress the algorithm as much as possible, but still
 keep the readability:<br>
<br>
&nbsp;&nbsp;&nbsp; public static boolean findPolyndrom(String polynd) {<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (polynd == null || &quot;&quot;.equals(polynd = polynd.toLowerCase().trim())) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int index = 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int length = polynd.length();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char forward = 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char reverse = 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boolean isValidString = false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (index &lt; length) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(!Character.isLetterOrDigit(forward = polynd.charAt(index&#43;&#43;))) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (index &gt;= length) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return isValidString;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(!Character.isLetterOrDigit(reverse = polynd.charAt(--length))) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (length &lt;= index) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return isValidString;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; isValidString = true;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (forward != reverse) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (length &lt;= index) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true;<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
<p>posted by vivemoire</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632639949200000000</link>
		<pubDate>Tue, 04 Oct 2005 03:55:20 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632639949200000000</guid>
		<dc:creator>vivemoire</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Try using my new non-KISS, très l33t solution to check any String for palindromosity.&nbsp; I'm sure Matz should add this to 1.8.4.<br>
<br>
#!/usr/bin/ruby<br>
<br>
#extend Ruby's built-in String class to allow palindrome checking, then give it a try!<br>
#public domain, november 25th, 2005 by dale anderson<br>
<br>
class String<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def palindrome?<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #normalize the string, result: s<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = self.gsub(/\W/, '').upcase<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #string length, half length<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sl = s.length<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hl = sl / 2<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # sl&nbsp;&nbsp;&nbsp; hl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SAMPLE FIGURES<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 8&nbsp;&nbsp;&nbsp;&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-3&nbsp;&nbsp;&nbsp;&nbsp; 4-7 &nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 7&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-2&nbsp;&nbsp;&nbsp;&nbsp; 4-6<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 6&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-2&nbsp;&nbsp;&nbsp;&nbsp; 3-5<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 5&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-1&nbsp;&nbsp;&nbsp;&nbsp; 3-4<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 4&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-1&nbsp;&nbsp;&nbsp;&nbsp; 2-3<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 3&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-0&nbsp;&nbsp;&nbsp;&nbsp; 2-2<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 2&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-0&nbsp;&nbsp;&nbsp;&nbsp; 1-1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 1&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-0&nbsp;&nbsp;&nbsp;&nbsp; 0-0 *<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 0&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0-0&nbsp;&nbsp;&nbsp;&nbsp; 0-0 *<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # * we observe that 0 and 1 are special cases<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true if sl &lt;= 1<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #compare the p1 versus the backwards p2<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p1 = s[ 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ..&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (hl-1)&nbsp; ]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p2 = s[ (sl-hl) ..&nbsp;&nbsp;&nbsp;&nbsp; (sl-1)&nbsp;&nbsp;&nbsp; ]<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #puts &quot; *** '#{p1}' vs. '#{p2}' ***&quot;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true if p1 == p2.reverse<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>
end<br>
<br>
<br>
<br>
tests = {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'pull-up' =&gt; true,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Oo.pSpOo' =&gt; true,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '' =&gt; true,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'A' =&gt; true,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '4321/abc\ba 1 2 3 4' =&gt; true,<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;hi there&quot; =&gt; false,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'mememe' =&gt; false<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
for potpal,georgeboole in tests<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise &quot;Potential Palindrome: '#{potpal}' was #{not georgeboole}!&quot; unless<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; potpal.palindrome? == georgeboole<br>
end<br>
<br>
Thanks for the video.&nbsp; <br>
<p>posted by ton_chat</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632685393270000000</link>
		<pubDate>Fri, 25 Nov 2005 18:15:27 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632685393270000000</guid>
		<dc:creator>ton_chat</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>My approach would have been to first solve the problem in the quickest (i.e. takes the shortest time to think of) way, likely using standard C&#43;&#43; library or the reverse-string approach. This would give me a chance to bring up the fact that I recognize that
 I'm being paid by the minute to write code and that I'm interested in protecting the company's bottom-line and not just to fool around with a small piece of code and waste time doing unnecessary embellishments and speed optimizations. Once I'm sure the interviewer
 gets my point about business considerations&nbsp;then I would qualify my first answer by saying however if the code proved (in about 2-3% of the time) to fall within the &quot;critical&quot; code category then I would next show the more efficient code (which I could be working
 out in my head while mindlessly presenting the more obvious but inefficient one). Plenty of techies are good at being playfully ingenious but precious few realize that it is also important to show one's bosses that one is shares their companies' bottomline
 concerns.</p>
<p>posted by bentan</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632714281660000000</link>
		<pubDate>Thu, 29 Dec 2005 04:42:46 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632714281660000000</guid>
		<dc:creator>bentan</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Using C# 2.0....<br>
<br>
public static bool IsPalindrome(string val)</p>
<p>{</p>
<p>&nbsp;&nbsp;&nbsp;char[] _chars = val.ToCharArray();</p>
<p>&nbsp;&nbsp;&nbsp;System.Array.Reverse(_chars);</p>
<p>&nbsp;&nbsp;&nbsp;string _reverseVal = new string(_chars);</p>
<p>&nbsp;&nbsp;&nbsp;return val.Equals(_reverseVal);</p>
<p>}</p>
<p>posted by IanB</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632764383950000000</link>
		<pubDate>Sat, 25 Feb 2006 04:26:35 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632764383950000000</guid>
		<dc:creator>IanB</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>This is my code, it is pretty good...<br>
if anyone destruct this, please tell me <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br>
<br>
<br>
bool isPalandrome( char* str ){<br>
&nbsp;bool result = true ;<br>
&nbsp;char *end = str &#43; strlen( str ) - 1;</p>
<p>&nbsp;while( str &lt; end )<br>
&nbsp;&nbsp;result &amp;= (((*(str&#43;&#43;)) ^ (*(end--))) == 0);<br>
&nbsp;return result;<br>
}</p>
<p>posted by emreknlk</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632982745350000000</link>
		<pubDate>Sat, 04 Nov 2006 22:02:15 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c632982745350000000</guid>
		<dc:creator>emreknlk</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Hi All!<br>
<br>
how about this <br>
code does take in account for characters you want to skip,<br>
but it does not check for case sensivivity<br>
<br>
pure c&#43;&#43;, not using any rtl<br>
avoiding checking for special case if string is &quot;ABA&quot; for example<br>
<br>
TCHAR ptszSkip[] = {' ', ',', '!', '-'};<br>
bool IsPalindrome(TCHAR* ptsz)<br>
{<br>
&nbsp;&nbsp; bool bRet = false;<br>
&nbsp;&nbsp; if(NULL != ptsz)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TCHAR* ptszEnd = ptsz;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(*ptszEnd != 0)&nbsp; //get&nbsp;end pointer<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#43;&#43;ptszEnd;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --ptszEnd;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bRet = true;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(ptsz &lt; ptszEnd)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool bDoCheck = true;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(size_t i = 0; i &lt; sizeof(ptszSkip)/sizeof(ptszSkip[0]); i&#43;&#43;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { /*check for skiped chars*/<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(*ptsz == ptszSkip[i])<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#43;&#43;ptsz;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bDoCheck = false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(*ptszEnd == ptszSkip[i])<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --ptszEnd;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bDoCheck = false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(bDoCheck)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(*ptsz != *ptszEnd) //as soon as find first not equal chars ,&nbsp; return false<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bRet = false;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#43;&#43;ptsz;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --ptszEnd;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; return bRet;<br>
}<br>
</p>
<p>posted by IgorZ</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c633107495180000000</link>
		<pubDate>Thu, 29 Mar 2007 07:18:38 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c633107495180000000</guid>
		<dc:creator>IgorZ</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[Ok, I know this is an old question, but I will post my code for the problem, but using 8bit chars, I think this does not change the overall solution : )
<br>
<br>
bool isPalyndrome(const char* aStr)<br>
{<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( aStr == NULL ) return false;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int size = strlen(aStr);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; --size;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for( int i = 0; i &lt; size/2; i&#43;&#43; )<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( aStr[i] != aStr[size -1 -i] )<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return true;<br>
&nbsp;}<br>
<p>posted by J.Marcelo Auler</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c633541080110000000</link>
		<pubDate>Tue, 12 Aug 2008 03:20:11 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c633541080110000000</guid>
		<dc:creator>J.Marcelo Auler</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<pre>Very, very late ;-) this handles whitespace and number etc (closer to a real palindrome rather than byte symmetry)<br> <br><br><font color="#3366ff">static bool</font> IsPalindrome(<font color="#3366ff">string</font> subject)<br>{<br>  <font color="#3366ff">const int</font> STEP_FORWARD = <font color="#ff0000">1</font>;<br>  <font color="#3366ff">const int</font> STEP_BACKWARD = -STEP_FORWARD;<br>  <font color="#3366ff">const int</font> BEFORE_START = -<font color="#ff0000">1</font>;<br>  <font color="#3366ff">const int</font> CHAR_AT_A_TIME = <font color="#ff0000">1</font>;<br>  <font color="#3366ff">const int</font> COMPARE_EQUALS = <font color="#ff0000">0</font>;<br><br><br><br>  <br>  <font color="#009900">// assume its not a palindrome</font><br>  <font color="#3366ff">bool</font> result = <font color="#3366ff">false</font>;<br><br>  <br><font color="#009900">  // how to compare</font><br>  CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;<br>  CompareOptions co =<br>    CompareOptions.IgnoreCase |<br>    CompareOptions.IgnoreKanaType |<br>    CompareOptions.IgnoreNonSpace |<br>    CompareOptions.IgnoreSymbols |<br>    CompareOptions.IgnoreWidth;<br><br>  <br><font color="#009900">  // null strings are not palindromes</font><br>  <font color="#3366ff">if</font> (subject != <font color="#3366ff">null</font>)<br>  {<br>    <font color="#3366ff">int</font> AFTER_END = subject.Length;<br>  <br>    <font color="#009900">// single letter words are palindromes</font><br>    result = (AFTER_END == <font color="#ff0000">1</font> &amp;&amp; IsPalindromeChar(subject[<font color="#ff0000">0</font>]));<br>  <br>    <font color="#009900">// start the comparison points at valid characters</font><br>    <font color="#3366ff">int</font> startOffset = GetNextValidCharacter(subject, BEFORE_START, STEP_FORWARD, AFTER_END);<br>    <font color="#3366ff">int</font> endOffset = GetNextValidCharacter(subject, AFTER_END, STEP_BACKWARD, BEFORE_START);<br>  <br>    <font color="#3366ff">while</font> (startOffset &lt; endOffset)<br>    {<br>      result = ci.Compare(subject, startOffset, CHAR_AT_A_TIME, subject, endOffset, CHAR_AT_A_TIME, co) == COMPARE_EQUALS;<br>    <br>      <font color="#3366ff">if</font> (!result)<br>        <font color="#3366ff">break</font>;<br><br>      <br>      <font color="#009900">// move the comparison points towards each other</font><br>      startOffset = GetNextValidCharacter(subject, startOffset, STEP_FORWARD, endOffset);<br>      endOffset = GetNextValidCharacter(subject, endOffset, STEP_BACKWARD, startOffset);<br>    }<br>  }<br> <br>  <font color="#3366ff">return</font> result;<br>}<br><br> <br><font color="#3366ff"><font color="#3366ff">static</font> int</font> GetNextValidCharacter(<font color="#3366ff">string</font> subject, <font color="#3366ff">int</font> offset, <font color="#3366ff">int</font> step, <font color="#3366ff">int</font> bound)<br>{<br>  <font color="#3366ff">if</font> (offset != bound)<br>    offset &#43;= step;<br><br>  <font color="#3366ff">while</font> (offset != bound &amp;&amp; !IsPalindromeChar(subject[offset]))<br>    offset &#43;= step;<br><br>  <font color="#3366ff">return</font> offset;<br>}<br> <br><font color="#3366ff">static bool</font> IsPalindromeChar(<font color="#3366ff">char</font> c)<br>{<br>  <font color="#3366ff">return char</font>.IsLetter(c) || <font color="#3366ff">char</font>.IsDigit(c);<br>}<br></pre>
<br>
more on <a href="http://blog.figmentengine.com/2008/08/man-plan-canal-panama.html">
palindromes on my blog</a><p>posted by FigmentEngine</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c633555270230000000</link>
		<pubDate>Thu, 28 Aug 2008 13:30:23 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c633555270230000000</guid>
		<dc:creator>FigmentEngine</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p>Rasx, You are correct! One problem - you are dealing with an insane environment. People that work at Microsoft are inbread and will never listen to you. The inbreeding has created genetic freaks that can solve number puzzles on a white board whether this
 measures the value of a potential employee or not.&nbsp;And as you so rightly point out, the exercise is silly and shows the defect of the inbreeding.
</p>
<p>posted by variable</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c633936880410000000</link>
		<pubDate>Fri, 13 Nov 2009 05:47:21 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c633936880410000000</guid>
		<dc:creator>variable</dc:creator>
	</item>
	<item>
		<title>Re: Gary Daniels and Evan Goldring - Mock whiteboard problem</title>
		<description>
			<![CDATA[
<p></p>
<div id="_mcePaste">bool is_palindrome(char *string) {</div>
<div id="_mcePaste"><span></span>int length = strlen(string);</div>
<div id="_mcePaste"><span></span></div>
<div id="_mcePaste"><span></span>for(int i = 0; i &lt; length / 2; &#43;&#43;i) {</div>
<div id="_mcePaste"><span></span>if (string[i] != string[length-i-1])</div>
<div id="_mcePaste"><span></span>return false;</div>
<div id="_mcePaste"><span></span>}</div>
<div id="_mcePaste"><span></span></div>
<div id="_mcePaste"><span></span>return true;</div>
<div id="_mcePaste">}</div>
<p>&nbsp;</p>
<pre class="brush: cpp">bool is_palindrome(char *string) {
	int length = strlen(string);
	
	for(int i = 0; i &lt; length / 2; &#43;&#43;i) {
		if (string[i] != string[length-i-1])
			return false;
	}
	
	return true;
}</pre>
<br>
<p>&nbsp;</p>
<p></p>
<p>posted by rxxjxxk</p>]]>
		</description>
		<link>http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c634036159870000000</link>
		<pubDate>Mon, 08 Mar 2010 03:33:07 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Blogs/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem#c634036159870000000</guid>
		<dc:creator>rxxjxxk</dc:creator>
	</item>
</channel>
</rss>