Python program to sort Palindrome Words in a Sentence
Given a string S representing a sentence, the task is to reorder all the palindromic words present in the sentence in sorted order.
Examples:
Input: S = “Please refer to the madam to know the level”
Output: Please level to the madam to know the refer
Explanation: Here “refer”, “madam”, “level” are the palindromic words. Sorting them generates the sequence {“level”, “madam”, “refer”}.Input: S = “refer to dad”
Output: dad to refer
Approach: Follow the steps below to solve the problem:
Below is the implementation of the above approach:
Python3
|
please level to the madam to know the refer
Time Complexity : O(N * logN)
Auxiliary Space : O(N)
Original page link
Best Cool Tech Gadgets
Top favorite technology gadgets
0 comments:
Post a Comment