Valid Palindrome With One Removal
EasyTwo Pointers · Meta
Given a string s of lowercase letters, return True if s is a palindrome or can be turned into one by deleting at most one character. Otherwise return False.
A palindrome reads the same forward and backward.
Example 1
- Input:
- s = "racecbar"
- Output:
- True
- Explanation
- Comparing from both ends, the first mismatch is
c(index 2) againstb(index 5). Deleting thebleavesracecar.
Example 2
- Input:
- s = "abcd"
- Output:
- False
- Explanation
- The first and last characters differ, and removing either one leaves a string whose ends still differ, so one removal is not enough.
Example 3
- Input:
- s = "deeee"
- Output:
- True
- Explanation
- Removing the leading
dleaveseeee. That is one removal, which is within the allowance.
Constraints
1 <= s.length <= 10^5sconsists of lowercase English letters