Given a string str. Check if it is possible to convert the string into palindrome string by changing only one character.
Input : str = "abccaa" Output : Yes We can change the second last character i.e. 'a' to 'b' to make it palindrome string Input : str = "abbcca" Output : No We can not convert the string into palindrome string by changing only one character.
Approach : The idea is simple, we check character str[i] with str[n-i-1]. If there is a mismatch, we increment count. If count of mismatches exceed 1, we return false. Else we return true.
Below is the implementation of above idea :
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.
- Palindrome by swapping only one character
- Make largest palindrome by changing at most K-digits
- Minimize the length of string by removing occurrence of only one character
- Make the string in AP by changing a character
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Minimum cost to convert string into palindrome
- Minimum reduce operations to convert a given string into a palindrome
- Minimum steps to convert one binary string to other only using negation
- Map every character of one string to another such that all occurrences are mapped to the same character
- Find the minimum number possible by changing at most one digit
- Convert vowels into upper case character in a given string
- Check if it is possible to convert one string into another with given constraints
- Sub-strings that start and end with one character and have at least one other
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Count all palindrome which is square of a palindrome
- Remove a character from a string to make it a palindrome
- Count substring of Binary string such that each character belongs to a palindrome of size greater than 1
- Generate a string which differs by only a single character from all given strings
- Permute a string by changing case
- Lengths of maximized partitions of a string such that each character of the string appears in one substring
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.