Almost Palindrome

Published by Helen Yu in

A string is an almost-palindrome if, by changing only one character, you can make it a palindrome. Create a function that returns true if a string is an almost-palindrome and false otherwise.

Examples

almost_palindrome("abcdcbg") ➞ true
# Transformed to "abcdcba" by changing "g" to "a".

almost_palindrome("abccia") ➞ true
# Transformed to "abccba" by changing "i" to "b".

almost_palindrome("abcdaaa") ➞ false
# Can't be transformed to a palindrome in exactly 1 turn.

almost_palindrome("1234312") ➞ false

Notes

Return false if the string is already a palindrome.

Watch a quick demo on how Edabit works.