Valid Palindrome

IF
AlgoAxiomStaff Engineers
JSTS
Easy20 mins

Given a string s, return true if it is a palindrome after converting all uppercase letters to lowercase and removing all non-alphanumeric characters.

A string is a palindrome if it reads the same forward and backward.

Examples

Example 1:

Input: s = "Madam, I'm Adam"

Output: true

Explanation: After removing non-alphanumeric characters and converting to lowercase, the string becomes "madamimadam", which is a palindrome.

Example 2:

Input: s = "race a car"

Output: false

Explanation: After processing, the string becomes "raceacar", which is not a palindrome.

Example 3:

Input: s = " "

Output: true

Explanation: After removing non-alphanumeric characters, the string becomes "". An empty string is considered a palindrome.

Constraints

  • 1 <= s.length <= 2 * 10⁵
  • s consists only of printable ASCII characters.
Source: Two Pointers pattern — AlgoAxiom
JavaScript
Test Case 1
root = [1, 2, 3]
Test Case 2
root = [1, 2, 3, 4, 5]
Idle