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.
- Make the string in AP by changing a character
- Remove a character from a string to make it a palindrome
- Minimum cost to convert string into palindrome
- Minimum reduce operations to convert a given string into a palindrome
- Count substring of Binary string such that each character belongs to a palindrome of size greater than 1
- Convert character array to string in C++
- Number of ways to convert a character X to a string Y
- Convert Character Array To String In Java
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Find the character in first string that is present at minimum index in second string
- Queries to find the first non-repeating character in the sub-string of a string
- Queries to find the last non-repeating character in the sub-string of a given string
- Minimum number of given operations required to convert a string to another string
- Convert string X to an anagram of string Y with minimum replacements
- Permute a string by changing case
- Convert Hexadecimal value String to ASCII value String
- Find a string such that every character is lexicographically greater than its immediate next character
- Modify the string such that every character gets replaced with the next character in the keyboard
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.