Skip to main content

Valid Palindrome

EasyPremium

Given a string s, return true if it is a palindrome, and false otherwise. A string is considered a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Write a function isPalindrome that implements this logic.

Examples

Input: s = "H123!@321h" Output: true Input: s = "race a car" Output: false

Constraints

  • 1 <= s.length <= 2 * 10^5
  • The input string s can include any printable ASCII characters.

Can you come up with a solution that achieves O(n) time complexity?

Can you come up with a solution that achieves O(1) space complexity?