218. Palindrome String by Recursion
Foundation1000 ms256 MBSolved by 0%
Print Yes if the string reads the same forwards and backwards, and No
otherwise.
The recursive shape is neat: a string is a palindrome when its first and last characters match AND the part between them is a palindrome. A string of length 0 or 1 is a palindrome with nothing to check.
That gives you two base cases, and noticing that both are needed is most of the problem.
Constraints - `1 ≤ length of s ≤ 200000`
Input
A single line containing a string s, made of printable characters with no spaces.
Output
Print Yes or No on one line.
Inputracecar
OutputYes
Noteis an odd-length palindrome
Inputabc
OutputNo
Noteis not a palindrome
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.