Loading...
Loading...
Rohan is making a word game for his college fest. A word wins a prize if it reads the same from left to right and from right to left, like malayalam or noon.
Given a word, print YES if it reads the same both ways, otherwise print NO. Solve it with a method that calls itself.
YES or NO.Example 1
Input
malayalam
Output
YES
The first and last letters match, and so does every pair inside.
Example 2
Input
abca
Output
NO
The outer letters match, but b and c in the middle do not.
Try the problem first. Open one hint at a time.
Look only at the first and the last letter. If they differ, the answer is already NO.
If they match, the word reads the same both ways exactly when the part between them does.
Pass two indexes, left and right, instead of cutting the string each time.
Stop when left >= right: an empty middle or a single letter reads the same both ways.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor