Closest Palindrome Problem Statement
You are given a string 'S' that represents a number. Your task is to find the closest palindromic number to this integer represented by 'S'. The closest number is defined as the one for which the absolute difference between the given integer represented by 'S' and the palindrome number is minimum. If multiple numbers have the same difference, return the smaller integer.
Example:
Input:
S = "121"
Output:
111
Explanation:
For the input 'S' = 121, the nearest palindromic numbers are 111 and 131. Both have the same absolute difference from 121, but 111 is smaller, so the answer is 111.
Constraints:
- 1 <= T <= 50
- 0 <= No of digits in 'S' <= 18
- Time Limit: 1 sec
Find the closest palindromic number to a given integer represented by a string.
Convert the string to an integer and iterate to find the closest palindromic number.
Check for palindromic numbers by reve...read more
Top Microsoft Corporation SDE-2 interview questions & answers
Popular interview questions of SDE-2
Top HR questions asked in Microsoft Corporation SDE-2
Reviews
Interviews
Salaries
Users/Month