![]() |
VOOZH | about |
Given a string s of size N. The task is to find lexicographically all the shortest palindromic substrings from the given string.
Examples:
Input: s= "programming"
Output: a g i m n o p r
Explanation:
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
Approach:
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 substrings 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)