Palindrome After At Most One Deletion
Problem statement
A palindrome reads the same from left to right and from right to left, like "level".
Given a string s, you may delete at most one character from it (or none). Return true if the result can be a palindrome, and false otherwise.
Function
canBePalindrome(s: String) → booleanExamples
Example 1
s = "racecxar"return = trueDelete the x to get "racecar", which reads the same both ways: true.
Example 2
s = "noon"return = trueThe string already reads the same both ways, so no deletion is needed: true.
Example 3
s = "abcab"return = falseDeleting a single character never helps: the five results are "bcab", "acab", "abab", "abcb" and "abca", and none reads the same both ways: false.
Constraints
1 <= s.length <= 10^4scontains only lowercase English letters