isPalindrome
Given a string, return true if the string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward. For this problem, ignore case and non-alphanumeric characters.
Examples
isPalindrome('A man, a plan, a canal: Panama') → true
isPalindrome('race a car') → false
Starter code
function isPalindrome(str) {
}
Complexity of the optimal solution
Time O(n), space O(n). The solution involves several O(n) operations: cleaning the string, splitting it into an array, reversing, and joining. A new string of length n is created, so both time and space are proportional to the input string length.