Given a string str some of whose characters are missing and are represented by a ‘*’. The task is to substitute the missing characters so as to make the lexicographically smallest palindrome. If it ot possible to make the string palindrome then print -1.
Input: str = “ab*a”
We can’t make it palindrome so output is -1.
- Place the ‘i’ marker at the starting of string and ‘j’ marker at the end of the string.
- If characters at both the positions are missing then substitute both the characters with ‘a’ so as to make it lexicographically smallest palindrome.
- If character at only ith or jth position is missing then replace it with jth or ith character respectively.
- If character at ith and jth positions are not equal then the string cannot be made into a palindrome and print -1.
Below is the implementation of the above approach:
- Make a lexicographically smallest palindrome with minimal changes
- Construct lexicographically smallest palindrome
- Missing characters to make a string Pangram
- Swap all occurrences of two characters to get lexicographically smallest string
- Print the arranged positions of characters to make 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
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Replace minimal number of characters to make all characters pair wise distinct
- Min flips of continuous characters to make all characters same in a string
- Count of lexicographically smaller characters on right
- Lexicographically smallest rotated sequence | Set 2
- Lexicographically smallest string of length N and sum K
- Lexicographically smallest and largest substring of size k
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.