Next Smaller Palindrome Problem Statement

You are provided with a palindrome number 'N' presented as a string 'S'. The task is to determine the largest palindrome number that is strictly less than 'N'.

Input:

The first line contains an integer T, the number of test cases.
For each test case, there is one line with a string 'S' which represents the palindrome number.

Output:

For each test case, output a single line containing the string representation of the largest palindrome that is less than 'S'.

Example:

Input:
T = 2
S = '12321'
S = '1000'
Output:
'12221'
'999'

Constraints:

  • 1 <= T <= 100
  • 1 <= |S| <= 104 (where |S| denotes the length of the string S)
  • The numerical value of 'S' is greater than 0.
Note:
  • A palindrome reads the same backward as forward, such as madam, racecar, 1234321.
  • A single-digit number is a palindrome.
  • The resulting number should not start with leading zeros, except when the answer is 0.
Be the first one to answer
Add answer anonymously...
Deutsche Bank Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter