Given a string, write a recursive function that check if the given string is palindrome, else not palindrome.
Input : malayalam Output : Yes Reverse of malayalam is also malayalam. Input : max Output : No Reverse of max is not max.
We have discussed an iterative function here.
The idea of recursive function is simple :
1) If there is only one character in string return true. 2) Else compare first and last characters and recur for remaining substring.
Below is the implementation of above idea :
This article is contributed by Sahil Rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Recursive program to check if number is palindrome or not
- String slicing in Python to check if a string can become empty by recursive deletion
- Function to copy string (Iterative and Recursive)
- Check if a given string is a rotation of a palindrome
- Check if any anagram of a string is palindrome or not
- Check if a string is palindrome in C using pointers
- C Program to Check if a Given String is Palindrome
- Check if it is possible to create a palindrome string from given N
- Given two strings check which string makes a palindrome first
- Check if there exists any sub-sequence in a string which is not palindrome
- Python program to check if a string is palindrome or not
- Check if a string can be rearranged to form special palindrome
- Python program to check if given string is vowel Palindrome
- Check if characters of a given string can be rearranged to form a palindrome
- Check if the characters in a string form a Palindrome in O(1) extra space
Improved By : nitin mittal