Given a palindromic string str and an integer N. The task is to find if it is possible to remove exactly N characters from the given string such that the string remains a palindrome.
Input: str = “abba”, N = 1
Remove ‘b’ and the reamianing string
“aba” is still a palindrome.
Input: str = “aba”, N = 1
Approach: It can be observed that it is always possible to remove any number of characters less than or equal to its length from a palindromic string such that the resultant string remains a palindromic string.
Below is the implementation of the above approach:
Time Complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if Matrix remains unchanged after row reversals
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Check if string is palindrome after removing all consecutive duplicates
- Maximum non-repeating characters after removing K characters
- Minimum sum of squares of character counts in a given string after removing k characters
- Check if permutation of a given string can be made palindromic by removing at most K characters
- Check if characters of a given string can be rearranged to form a palindrome
- Print string after removing all (“10” or “01”) from the binary string
- Find longest palindrome formed by removing or shuffling chars from string
- Count of ungrouped characters after dividing a string into K groups of distinct characters
- Minimum number of characters to be replaced to make a given string Palindrome
- Minimize cost to empty a given string by removing characters alphabetically
- Minimum length of Run Length Encoding possible by removing at most K characters from a given string
- Check if the characters in a string form a Palindrome in O(1) extra space
- Minimum removal of characters required such that permutation of given string is a palindrome
- Character replacement after removing duplicates from a string
- Balance a string after removing extra brackets
- Find the resultant String after replacing X with Y and removing Z
- Print reverse string after removing vowels
- Ways of transforming one string to other by removing 0 or more characters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.