PALIN - The Next Palindrome

A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output. Numbers are always displayed without leading zeros.


The first line contains integer t, the number of test cases. Integers K are given in the next t lines.


For each K, output the smallest palindrome larger than K.




Warning: large Input/Output data, be careful with certain languages

hide comments
surfeyone: 2020-05-24 00:26:44

0 -> 1
1 -> 2
2 -> 3
9 -> 11
99 -> 101
999 -> 1001
9898 -> 9999

kauai68: 2020-05-17 16:48:29

There are no leading zeros.

wahidmshafin: 2020-05-16 21:00:15

Try for these test cases

You need to get rid of the leading zeros

kauai68: 2020-05-10 18:28:28

I've got AC and I don't think that the implementation is difficult. Nice C++ code needs less than 80 lines of code.

Last edit: 2020-05-10 18:29:45
khoaph: 2020-05-10 03:34:49

Thanks @trulyness for the extra test cases
Got some wa because of not having awared of them.

Last edit: 2020-05-10 03:36:16
manishsaini4u: 2020-05-09 05:30:08

can anyone explain what problem says?

meher_24: 2020-05-07 16:17:01

do i just increment the input by one and check if its a palindrome or is there a better and a faster method?

hritik_1105: 2020-05-07 06:23:05

Its logic is easy but implementation is hard.
It took me one complete day to make logic that covers all cases and then AC in 1 go.

bernard_mocko1: 2020-05-04 01:09:54

When they say, that elements are not more than 1000000 digits, they are not joking, my char array in C was one element to short

Last edit: 2020-05-04 01:17:10
fawad: 2020-04-25 09:54:46

guys, there is space character after input in every line, just take care of it

Added by:adrian
Time limit:2s-9s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6

Problem's scores 1 vote

Concept difficulty
Concept difficulty 37%
Implementation difficulty
Implementation difficulty 50%
458 16