Next Smallest Palindrome
Submissions: 7361   Accuracy:

27.21%

  Difficulty: Hard   Marks: 8

Given a number, in the form of an array a[] containing digits from 1 to 9(inclusive). The task is to find the next smallest palindrome larger than this number.

Input :
The first line is number of test cases T. Every testcase contains two lines. The first line contains the size of the array, second line contains the digits of the number separated by space.

Output:
In each separate line print the digits of palindrome with spaces in between.

Constraints:
1<=T<=100
1<=n<=1000
1<=a[i]<=9

Example:
Input:
1
11
9 4 1 8 7 9 7 8 3 2 2

Output:
9 4 1 8 8 0 8 8 1 4 9

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: JASPREET Singh
Author: abhiraj26


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.