Interview question: Palindrome String

Given a string, you need to determine whether it is a palindrome or not.

A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. For example, "racecar" is a palindrome because if you reverse the order of its letters, you still get "racecar". Similarly, "level", "deified", and "A man a plan a canal Panama" are all palindromes.

Write a function that takes a string as input and returns true if the string is a palindrome, or false otherwise.

For the purposes of this problem, you should ignore any non-alphanumeric characters and treat upper-case and lower-case letters as the same character.

Example 1

Input: s = "racecar"
Result: true

Example 2

Input: s = "a"
Result: true

Example 3

Input: s = "hello"
Result: false

Example 4

Input: s = "A man, a plan, a canal: Panama"
Result: true

Test

Results