Originally Posted by dmmik
Here is a whiteboard C coding question I was asked at an actual game company interview. Complete this function:
bool IsPalendrome(char* str)
Apologies for thread resurrection.
I saw this last night while browsing, and it's a nice little problem, if not especially taxing. As a novice, I originally thought it would be best to break it down into an array and do something complicated such as reversing the order of the array and then comparing them. But there is no need - after further reading, having seen the string tools available. Once I was thinking along those lines, it took about 20 mins.
So here's a solution (in python rather than C) - anyone got any optimisation tips?
length = len(string)
while j > 0:
if string[i] == string[j-1]:
print 'Not a palindrome'
if j == 0:
print 'Word is a palindrome'
input = raw_input()
The mild advantage of this is that it's not typed, so works equally well with palindromic numbers. For the c problem, I guess you'd have to put in some type checking to sanitise the input before doing anything.