Description

Given a string s, return true if the s can be palindrome after deleting at most one character from it.

Examples

Input:s = "aba"
Output:true
Explanation:

The string 'aba' already reads the same forwards and backwards, so no deletion is needed. It is possible to delete 0 characters (which is at most 1).

Input:s = "abca"
Output:true
Explanation:

Comparing 'a' and 'a' at ends matches. Comparing 'b' and 'c' fails. trying skipping 'c' at index 2, leaving 'aba' which is a valid palindrome.

Input:s = "abc"
Output:false
Explanation:

No single deletion makes the string a palindrome, so the answer is false.

Constraints

  • 1 ≤ s.length ≤ 10⁵
  • s consists of lowercase English letters.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!