Given a sentence str. The problem is to remove all the palindromic words from the given sentence.
Input : str = "Text contains malayalam and level words" Output : This contains and words Input : str = "abc bcd" Output : abc bcd
Approach: One by one extract all the words. Check if the current word is not a palindrome then add it to the final string.
removePalinWords(str, n) Initialize final_str = "", word = "" str = str + " " for i = 0 to n-1 if str[i] != ' ', then word = word + str[i] else if (!(isPalindrome(word)), then final_str += word + " " word = "" return final_str
isPalindrome() function is used to check whether the given string is palindrome or not. Refer this post.
Text contains and words
Time Complexity: O(n).
- Count palindrome words in a sentence
- Number of palindromic permutations | Set 1
- Count special palindromes in a String
- Sparse Search
- Maximum segment value after putting k breakpoints in a number
- Prefix to Infix Conversion
- Prefix to Postfix Conversion
- Rearrange characters to form palindrome if possible
- Check for Palindrome after every character replacement Query
- Different methods to reverse a string in C/C++
- Print all palindrome permutations of a string
- Count characters with same neighbors
- Rearrange the string to maximize the number of palindromic substrings
- Program to find remainder when large number is divided by r
- Replace minimal number of characters to make all characters pair wise distinct
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.