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)
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Check if characters of a given string can be rearranged to form a palindrome
- Check if the characters in a string form a Palindrome in O(1) extra space
- Minimum number of characters to be replaced to make a given string Palindrome
- Find longest palindrome formed by removing or shuffling chars from string
- Ways of transforming one string to other by removing 0 or more characters
- Reduce the string by removing K consecutive identical characters
- Minimum sum of squares of character counts in a given string after removing k characters
- Find if string is K-Palindrome or not using all characters exactly once
- Check if a doubly linked list of characters is palindrome or not
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Find the player who rearranges the characters to get a palindrome string first
- Minimum characters to be added at front to make string palindrome
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Check if any anagram of a string is palindrome or not
- C Program to Check if a Given String is Palindrome
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.