Loading...
Loading...
Loading...
A word game gives points if a word is a palindrome, or can become one by deleting at most one letter. Read a word and print YES if that is possible and NO otherwise.
YES or NO.Example 1
Input
abca
Output
YES
Delete b (or c) to get aca (or aba).
Example 2
Input
abc
Output
NO
Try the problem first. Open one hint at a time.
Use two indexes from both ends and move them inward while the letters match.
At the first mismatch you must delete one of the two letters. Try both: is the part without the left letter a palindrome, or the part without the right letter?
A helper method isPalindrome(word, left, right) that checks one range keeps the code short.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor