696. Check Palindrome Using Recursion

EasyRecursionRecursion

Given a string s, return true if it is a palindrome, false otherwise. Use recursion — compare the first and last characters, then recurse on the inner substring. The check is case-sensitive.

Input: A single string s (0 ≤ len(s) ≤ 1000).

Output: A boolean: true if s is a palindrome, false otherwise.

Examples

Example 1
Input: "racecar"
Output: true
Explanation: "racecar": r==r, so check "aceca": a==a, check "cec": c==c, check "e": length 1 → true.
Example 2
Input: "hello"
Output: false
Explanation: "hello": h≠o → immediately false.
Example 3
Input: "a"
Output: true
Explanation: Single character is always a palindrome.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →