Valid Palindrome

Easy
Concept
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Valid Palindrome

Approach

First clean the string by filtering to only lowercase alphanumeric characters. Then use two converging pointers from both ends, comparing characters inward. Return false on the first mismatch or true if all pairs match.

Complexity Analysis

Time
O(n)
Space
O(n)

Pattern

Two Pointers (Converging)

Why It Works

A palindrome reads the same forwards and backwards, so comparing symmetric positions from the outside in detects any asymmetry in at most n/2 comparisons.

Updated Feb 2026