| Topic | Difficulty | Companies |
|---|---|---|
| Mathematical Algorithms | HARD | Microsoft Amazon |
Given an integer num, write a program to find the closest palindrome to integer num. (excluding num). The output need not be larger than num. It can be smaller or larger than num.
Problem Note
num is a positive integer represented by a string, whose length will not exceed 15 digits.num and there is a tie between them, then return the smaller one as output.Example 1
Input: "99"
Output: "101"
Explanation: "88" and "101" are two nearest integers which are palindrome. But "101" is the answer because the absolute difference is minimum between "99" and "101".