Valid Palindrome II

easy

Check if string can be a palindrome by removing at most one character

Valid Palindrome II

Key Insight

On mismatch try skipping left or right — if either substring is palindrome, return true.

Step 1Setup
a == a ✓
left
a
0
b
1
c
2
right
a
3
converge

Check if "abca" can be palindrome with at most one deletion. left=0, right=3.

1 / 5

Learn the Pattern

Practice the Code

Step-by-Step Walkthrough: Valid Palindrome II

On mismatch try skipping left or right — if either substring is palindrome, return true.

  1. Setup

    Check if "abca" can be palindrome with at most one deletion. left=0, right=3.

  2. Move Inward

    Outer chars match. Move inward: left=1, right=2. Mismatch found.

  3. Try Skip Left

    Skip left char: check substring s[2..2] = "c". Single char is palindrome ✓

  4. Try Skip Right

    Skip right char: check substring s[1..1] = "b". Single char is palindrome ✓

  5. Result

    At most one deletion needed. Either skip produces a palindrome.