Algorithm to check if a word is a palindrome
The question
Given a word, verify if it is a palindrome excluding spaces and punctuation.
The solution
This is the algorithm I came up to find out if a word is a palindrome:
– Place a pointer(left) on the first character
– Place a pointer(right) on the last character
– Check if the element at left is a character (not punctuation or space)
– If the element is not a character move the pointer one space to the right until you find a character
– Check if the element at right is a character
– If the element is not a character move the pointer one space to the left
– If left is greater than right return true
– Check if left and right elements are the same
– If they are not the same return false
– If they are the same move left one space to the right and right one space to the left
– Start over from step three