218. Palindrome String
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
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution