Earlier quoted context omitted.
Nothing more complicated than this: is_a_palindrome(S) { assert is_a_string(S) if reverse(S) == S return true return false } A string is a palindrome if it's equal to itself reversed. The example "solution" in the article is dreadfully overengineered to death and back. Noone interviewing should be happy to see such a solution and noone being interviewed should expect to be required to give such a solution, to such a…
That solution would fail to catch several of the examples that were requested to be caught. Sometimes something that appears overengineered is built that way to meet the actual requirements a problem presents.
That's poppycock. Here are the requirments:
>> Write the most efficient function you can that determines whether a given string is a palindrome.
A palindrome is a string that is equal to itself reversed. That's like, the mathematical definition of a palindrome (simplified, of course). What I gave you catches exactly that. If some of the test cases in the proposed solution don't agree with the commonly accepted definition that's a problem of the proposed solution, not mine.
Also, in terms of the "most efficient" solution, the guy's proposed solution is far from that- because he tries to be smart and reverse the string while he compares it, thinking that's faster than going the whole hog. But that's only going to save you some cycles a tiny amount of the time, because the vast majority of strings you can expect to encounter are unlikely to be palindromes. Reversing and comparing the string to itself is the neatest, quickest, most legible and prettiest thing you can do in this case, regardless of your use case or anything else.
And if you're a recruiter that expects anything else, that's because you have no idea what you're looking for, not because you are as smart as you think you are.