title: Closest Palindrome Number
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>Algorithm steps are:</p>
  
  <ul>
  <li>Convert the number into string.</li>
  <li>copy first half to second half in reverse order</li>
  <li>convert to number and measure the abs. difference with original number diff1</li>
  <li>add 1 to half string and now copy first half to second half in reverse order</li>
  <li>convert to number and measure the abs. difference with original number diff2</li>
  <li>if diff1 is less than diff2 return first number else return second number</li>
  </ul>