dsa · easy

Valid Palindrome II

Return whether s can become a palindrome after deleting **at most one** character (including deleting none). A palindrome reads the same forwards and backwards.

Arguments

Example

s = "aba" is already a palindrome → true.

s = "abca": delete c (or b) and "aba" (or "aca") is a palindrome → true.

s = "abc" still fails after any single deletion → false.

Constraints

1 <= s.length <= 10^5 s contains only lowercase English letters. Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
'aba'

Expected:
true

Example 2

Input:
'abca'

Expected:
true

Example 3

Input:
'abc'

Expected:
false

Open in the Dojo editor