A security vault accepts a passphrase only if it reads the same forwards and backwards. To be a little more forgiving, the vault will also accept a passphrase that becomes a palindrome after deleting at most one character from it, with the remaining characters keeping their original order. Given a candidate passphrase, decide whether the vault accepts it.
The only line of input is the passphrase s.
Print YES if s is already a palindrome, or can become one by deleting exactly one character, and NO otherwise.
Example 1
Input
abca
Expected
YES
Explanation
Deleting the 'b' leaves "aca", which reads the same forwards and backwards, so a single deletion is enough and the answer is YES.
Example 2
Input
abc
Expected
NO
Explanation
s itself is not a palindrome, and deleting any single character produces "bc", "ac", or "ab", none of which are palindromes either, so no single deletion fixes it and the answer is NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →