DSA problem
Valid Palindrome II
Given a string s, return true if s can be a palindrome after deleting at most one character from it.
The string consists of lowercase English letters only, so no case folding or character filtering is required. Deleting zero characters is allowed, so any string that is already a palindrome trivially satisfies the condition.
The challenge is to decide, when a mismatch is found, whether skipping the left character or the right character can still yield a palindrome.
Examples
Example 1
Input:
s = "aba"Output:
trueExplanation: "aba" is already a palindrome, so zero deletions are needed.
Example 2
Input:
s = "abca"Output:
trueExplanation: Deleting the character 'c' yields "aba", which is a palindrome.
Example 3
Input:
s = "abc"Output:
falseExplanation: No single deletion can make "abc" a palindrome.
Constraints
- 1 <= s.length <= 10^5
- s consists of lowercase English letters.
3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.