Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, I'm saying you are a bad programmer if, after being told what a palindrome is, you cannot invent an algorithm that tests whether a string is a palindrome.

It's pretty simple: a palindrome is something that is the same backwards as it is forwards.

Just from the definition, the naive/brute force solution is obvious: given a string or a list or any other kind of sequence, make a reversed copy of it and check to see if the reversed copy is identical to the original. You don't even need to be a programmer to figure out that approach -- anyone could do it with a pen and paper.

After that, the challenge is to write some code that can do this, and to do it more efficiently, i.e. without making a copy. That's not too hard either, because one of the popular methods that is used to reverse a string (another popular "warmup" interview question) can also be used to verify if a string is a palindrome in O(n) time and O(1) space.

I've seen far more difficult questions on phone screens, not to mention onsite interviews.



Ah, okay. Thanks for explaining a bit better. There are definitely programmers out there who would call someone an idiot if they don't know what a palindrome or other [insert college CS problem here].




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: