VOOZH about

URL: https://www.geeksforgeeks.org/dsa/lexicographically-all-shortest-palindromic-substrings-from-a-given-string/

⇱ Lexicographically all Shortest Palindromic Substrings from a given string - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lexicographically all Shortest Palindromic Substrings from a given string

Last Updated : 7 Mar, 2022

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: 


Output: 
e f g k o r s

 

Time Complexity: O(N), where N is the size of the string.
Space Complexity: O(1)
 

Comment
Article Tags: