Next Smallest Palindrome Problem Statement

Find the next smallest palindrome strictly greater than a given number 'N' represented as a string 'S'.

Explanation:

You are given a number in string format, and your task is to determine the smallest numeric palindrome that is strictly greater than the given number.

Input:

The first line contains an integer 'T', the number of test cases.
The first line for each test case includes an integer, the number of digits in 'N'.
The second line for each test case contains the string 'S'.

Output:

Return the next greater palindrome as a string for each test case.

Example:

Suppose the input is:

Input:
T = 1
N = 3
S = "123"
Output:
"131"
Explanation:

The next smallest palindrome greater than '123' is '131'.

Constraints:

  • 1 <= T <= 100
  • 1 <= len(S) <= 10^4

Note:

  • A palindrome reads the same backward as forward, e.g., 'naman', 'abcba', '1234321'.
  • The given string 'S' represents a numerical value greater than 0.
  • Single-digit numbers are also considered palindromic.
  • The length of 'S' is the number of digits in 'N'.
  • Implementation does not require printing; only return the result.
AnswerBot
4mo

Find the next smallest palindrome greater than a given number represented as a string.

  • Iterate from the middle of the number and mirror the left side to the right side to create a palindrome

  • If the resu...read more

Help your peers!
Select
Add answer anonymously...

VMware Software Member Technical Staff interview questions & answers

A Member Technical Staff was asked Q. Convert Array to Min Heap Task Given an array 'ARR' of integers with 'N' element...read more
A Member Technical Staff was asked Q. Tower of Hanoi Problem Statement You have three rods numbered from 1 to 3, and '...read more
A Member Technical Staff was asked Q. What is a page fault?

Popular interview questions of Member Technical Staff

A Member Technical Staff was asked Q1. Convert Array to Min Heap Task Given an array 'ARR' of integers with 'N' element...read more
A Member Technical Staff was asked Q2. Tower of Hanoi Problem Statement You have three rods numbered from 1 to 3, and '...read more
A Member Technical Staff was asked Q3. What is a page fault?
VMware Software Member Technical Staff Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits