Valid Palindrome

easy

Check if string is palindrome (ignoring non-alphanumeric)

Valid Palindrome

Key Insight

Compare characters from both ends, skip non-alphanumeric, move inward

Step 1Clean String
left
a
0
m
1
a
2
n
3
a
4
p
5
l
6
a
7
n
8
a
9
c
10
a
11
n
12
a
13
l
14
p
15
a
16
n
17
a
18
m
19
right
a
20
converge

"A man, a plan, a canal: Panama" → "amanaplanacanalpanama"

1 / 5

Learn the Pattern

Practice the Code

Step-by-Step Walkthrough: Valid Palindrome

Compare characters from both ends, skip non-alphanumeric, move inward

  1. Clean String

    "A man, a plan, a canal: Panama" → "amanaplanacanalpanama"

  2. Compare Ends

    Compare "a" at left with "a" at right. They match!

  3. Move Inward

    Both pointers move. Compare "m" with "m".

  4. Continue to Center

    Keep comparing until pointers meet at center.

  5. Valid Palindrome

    All pairs matched. It's a palindrome!