Generalize isPalindrome