Valid Palindrome II

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 II

Approach

Use converging two pointers from both ends. When a mismatch is found, try two options: skip the left character or skip the right character. Check if either remaining substring forms a palindrome. If so, the original string is a palindrome with one deletion.

Complexity Analysis

Time
O(n)
Space
O(1)

Pattern

Two Pointers (Converging)

Why It Works

A mismatch gives exactly two recovery options. Only one character can be removed, so trying both skip-left and skip-right covers all possibilities without backtracking.

Updated Feb 2026