Skip to main content
Back to problems
Leetcode
Easy
Two Pointers
Strings
Valid Palindrome

Determine whether a string is a palindrome after ignoring non-alphanumeric characters and case.

Acceptance 0%
Problem Statement

Given a string, decide whether it reads the same forward and backward after:

  • ignoring all characters that are not letters or digits, and
  • treating uppercase and lowercase letters as equal.

Return true if the cleaned string is a palindrome; otherwise return false.

A palindrome is a sequence that matches its reverse.

Input Format

  • A single string s.
  • The string may contain letters, digits, spaces, punctuation, and other visible characters.

Output Format

  • Return a boolean value:
    • true if s is a valid palindrome under the rules above
    • false otherwise

Constraints

  • 0 <= s.length
  • The string length is small to moderate for interview-style checking.
  • You should solve it without building unnecessary extra structures when possible.
Examples
Sample cases returned by the problem API.

Example 1

Input

s = "A man, a plan, a canal: Panama"

Output

true

Explanation

After removing punctuation and spaces and converting to lowercase, the string becomes amanaplanacanalpanama, which is the same forward and backward.

Example 2

Input

s = "race a car"

Output

false

Explanation

The cleaned string is raceacar, which does not match its reverse.

Show 1 more example

Example 3

Input

s = " "

Output

true

Explanation

There are no alphanumeric characters, so the cleaned string is empty and is considered a palindrome.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.