Given a string s of size N. The task is to find lexicographically all shortest palindromic substrings from the given string.
Input: s= “programming”
Output: a g i m n o p r
The Lexicographical shortest palindrome substring for the word “programming” will be the single characters from the given string. Hence, the output is : a g i m n o p r.
Input: s= “geeksforgeeks”
Output: e f g k o r s
To solve the problem mentioned above the very first observation is that the shortest palindromic substring will be of size 1. So as per the problem statement, we have to find all distinct substring of size 1 lexicographically which means all the characters in the given string.
Below is the implementation of the above approach:
e f g k o r s
Time Complexity: O(N), where N is the size of the string.
Space Complexity: O(1)
- Lexicographically first palindromic string
- Find the lexicographically largest palindromic Subsequence of a String
- Make the string lexicographically smallest and non palindromic by replacing exactly one character
- Check if a string can be split into even length palindromic substrings
- Rearrange the string to maximize the number of palindromic substrings
- Permutation of given string that maximizes count of Palindromic substrings
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Shortest Palindromic Substring
- Count all Prime Length Palindromic Substrings
- Count of Palindromic substrings in an Index range
- Count of K-size substrings having palindromic permutations
- Make palindromic string non-palindromic by rearranging its letters
- 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
- Lexicographically smallest string whose hamming distance from given string is exactly K
- Generate a string whose all K-size substrings can be concatenated to form the given string
- Longest palindromic string formed by concatenation of prefix and suffix of a string
- Find the count of palindromic sub-string of a string in its sorted form
- Find a palindromic string B such that given String A is a subsequense of B
- Check if a string contains a palindromic sub-string of even length
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.
Improved By : AnkitRai01