Closest Palindrome Number
Closest Palindrome Number I came across one of the common interview question which was to find the closest palindrome number. Say if the input is 127 then output will be 131 and if it is 125 then it should give 121 as output. I can come up with the logic but my logic fails on certain cases like 91, 911. In these inputs it give 99 , 919 but the correct output is 88 and 909. Algorithm steps are: Sometimes there's a tie: the closest palindromes to 1000 are 1001 and 999. I think it can be established that there is always one closest palindrome that has the same number of digits. However, as you noted, the closest palindrome may share no digits in common with the number. – Ted Hopp Sep 24 '13 at 17:50 Folding the string as you describe gives one of the closest palindromes, either upper ...