Given a string, find the next smallest palindrome
You are given a number 'N' in the form of a string 'S', your task is to find the smallest number strictly greater than the given number 'N' which is a palindrome.
Note:
1) A palindrome is a word, number, phrase, or another sequence of characters that reads the same backward as forward, such as 'naman', 'abcba', '1234321', etc
2) The numerical value of the given string 'S' will be greater than 0.
3) A single-digit number is also considered as a palindrome.
4) Note that the length of the string 'S' is nothing but the number of digits in the number 'N'.
Input Format:
The first line of the input contains an integer 'T' denoting the number of test cases.
The first line of each test case contains an integer, denoting the number of digits in the number 'N' (i.e. the length of the string).
The second line of each test case contains the string 'S'.
Output Format:
The only line of output of each test case consists of the next greater palindromic number(as described in the problem statement) returned in the form of a string.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 100
1 <= len(S) <= 10^4
Time Limit : 1 sec
CodingNinjas
author
2y
Palindromic String
In this method, Before we start let us define what is the right half (or right part) and what is left half (or left part) in the string. There can be two cases based on the length of...read more
Help your peers!
Add answer anonymously...
Top VMware Software Member Technical Staff interview questions & answers
Popular interview questions of Member Technical Staff
Top HR questions asked in VMware Software Member Technical Staff
>
VMware Software Member Technical Staff Interview Questions
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app