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

Check whether a string can become a palindrome after deleting at most one character.

Acceptance 0%
Problem Statement

Given a string s, determine whether it can be converted into a palindrome by removing at most one character.

A palindrome reads the same forward and backward. You may choose to delete zero characters as well, which means an already-palindromic string should return true.

Return true if the string can be made into a palindrome after at most one deletion, otherwise return false.

Input Format

  • A single string s.
  • The string contains lowercase English letters in the standard LeetCode formulation.

Output Format

  • Return true if s can be a palindrome after deleting at most one character.
  • Otherwise return false.

Constraints

  • 1≤∣s∣≤1051 \le |s| \le 10^5
  • s contains lowercase English letters.
  • You may delete at most one character.
Examples
Sample cases returned by the problem API.

Example 1

Input

s = "aba"

Output

true

Explanation

The string is already a palindrome, so no deletion is needed.

Example 2

Input

s = "abca"

Output

true

Explanation

Deleting either b or c makes the string a palindrome ("aca" or "aba").

Show 1 more example

Example 3

Input

s = "abc"

Output

false

Explanation

No single deletion can turn it into 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.