A palindrome after one deletion
A palindrome reads the same from both ends, like "level". Return whether s can be made into a palindrome by deleting at most one of its characters.
A string that is already a palindrome counts: you may delete nothing.
- Input
s = "abcca"- Output
true
Deleting the "b" leaves "acca".
- Input
s = "level"- Output
true
It is already a palindrome.
- Input
s = "abcd"- Output
false
Every single deletion still leaves letters that do not match.
Limits
1 <= s.length <= 100000s holds lowercase English letters
Hints
Hint 1
Compare from both ends inward. While the letters match, nothing needs deleting.
Hint 2
At the first mismatch one of those two letters must be the deleted one. Check whether the rest is a palindrome after skipping the left one, or after skipping the right one. No further deletion is allowed.
Where this was reported
- Meta, New grad onsite, 2022 (LeetCode)
Our own problem on the task these candidates describe; the wording, examples and tests are InternDoor’s.
Run your code to check it on the examples. Submit runs every hidden test.
