Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Palindrome

Easy Acceptance 90.00% Points 20.00

You are given a string s. Your task is to check whether the string is a palindrome using recursion only. A string is called a palindrome if it reads the same forward and backward.

Return true if the string is a palindrome; otherwise, return false.

Examples
Example 1

Example 1

Input: s = "madam"

Output: true

Explanation: The string reads the same from left to right and right to left.

Example 2

Example 2

Input: s = "hello"

Output: false

Explanation: The string is different when reversed.

Example 3

Example 3

Input: s = "a"

Output: true

Explanation: A single character is always a palindrome.

Hints
Hint 1
N/A
Constraints
  • 1 = length of s = 105
  • The string contains printable characters only
Companies
Microsoft ZScaler Mastercard
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions