You are given a string s(only lowercase alphabets) with length n. Print the position of every character of the String it must acquire so that it will form a palindromic string.
Input : c b b a a Output : 3 1 5 2 4 To make string palindrome 'c' must be at position 3, 'b' at 1 and 5, 'a' at 2 and 4. Input : a b c Output : Not Possible Any permutation of string cannot form palindrome .
The idea is to create an array of vectors (or dynamic size array) which stores all positions of every character. After storing positions, we check if count of odd characters is more than one. If yes, we return “Not Possible”. Otherwise, we first print first half positions from the array, then one position of odd character (if it is present) and finally second half positions.
2 1 4 5 7 6 3
Time Complexity : O ( n )
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.
- Number of positions where a letter can be inserted such that a string becomes palindrome
- Minimum characters to be added at front to make string palindrome
- Minimum number of characters to be replaced to make a given string Palindrome
- Make lexicographically smallest palindrome by substituting missing characters
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- Find the sum of the ascii values of characters which are present at prime positions
- Min flips of continuous characters to make all characters same in a string
- Replace minimal number of characters to make all characters pair wise distinct
- Minimum characters to be replaced to make frequency of all characters same
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Count all palindrome which is square of a palindrome
- Check if a doubly linked list of characters is palindrome or not
- Check if characters of a given string can be rearranged to form a palindrome
- Next word that does not contain a palindrome and has characters from first k
- Find if string is K-Palindrome or not using all characters exactly once
- Rearrange characters to form palindrome if possible
- Check if the characters in a string form a Palindrome in O(1) extra space
- Find the player who rearranges the characters to get a palindrome string first
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Maximum length palindrome that can be created with characters in range L and R
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
Improved By : 29AjayKumar