## Tuesday, May 16, 2017

### Problem Statement

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Example:

```"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.
```

Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.

### Solution

 ``` 1 2 3 4 5 6 7 8 9 10 11 12``` ```def isPalindrome(s): head,tail=0,len(s)-1 while head < tail: while head
• We need 2 pointers head and tail
• Head is the initial position and tail is the last position in the array
• Increment the header if we do not find valid character .Decrement the tail if we do not find the valid character.
• Loop through the array till we find tail is greater than head
• Return false if header character is not equal to tail
```public static boolean get(String str)
{
//if string is empty return true
if(str.isEmpty())
{
return true;
}
//loop  through the strings to find if it is a valid palindrome
{
//Increment the header if the character isLetter or digit
}
//Decrement the tail if the character isLetter or digit
else if(!Character.isLetterOrDigit(str.charAt(tail))){
tail--;
}
else {
```                                     !=Character.toLowerCase(str.charAt(tail)))
{
return false;
}