Given a string str. The string may contain lower-case letters, special characters, digits or even white-spaces. The task is to check, whether only the letters present in the string are forming a Palindromic combination or not without using any extra space.
Note: It is not allowed to use extra space to solve this problem. Also, the letters present in the string are in lower-case and the string may contain special characters, digits or even white-spaces along with lowercase letters.
Input : str = “m a 343 la y a l am”
Output : YES
The characters in the string form the sequence “malayalam”, which is a palindrome.
Input : str = “malayalam”
Output : YES
- Create two utility functions to get the first and last position of characters present in the string.
- Start traversing the string, and keep finding the position of first and last characters everytime.
- If the first and last characters are same for every iteration and the string is traversed completely then print YES otherwise print NO.
Below is the implementation of above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if characters of a given string can be rearranged to form a palindrome
- To check a number is palindrome or not without using any extra space
- Check if a string can be rearranged to form special palindrome
- Check if string remains palindrome after removing given number of characters
- Check if characters of one string can be swapped to form other
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Length of longest palindrome list in a linked list using O(1) extra space
- Rearrange characters to form palindrome if possible
- Remove duplicates from a string in O(1) extra space
- Replace all occurrences of string AB with C without using extra space
- Sum of all substrings of a string representing a number | Set 2 (Constant Extra Space)
- Find if string is K-Palindrome or not using all characters exactly once
- Check if a doubly linked list of characters is palindrome or not
- Minimal moves to form a string by adding characters or appending string itself
- Find the player who rearranges the characters to get a palindrome string first
- Minimum characters to be added at front to make string palindrome
- Minimum number of characters to be replaced to make a given string Palindrome
- Check if a given string is Even-Odd Palindrome or not
- Check if it is possible to create a palindrome string from given N
- Check whether the given string is Palindrome using Stack
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.