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
Piotrek Nicowski: 2018-03-23 20:39:46

@prabhakar2050 - For each K, output the smallest palindrome *** LARGER THAN *** K.

prabhakar2050: 2018-03-17 20:26:29

isnt 808 a palindrome? In the test case, it isnt. but on the net it clearly mentions its a palindrome. What should i do?

techymj: 2018-03-13 05:43:21

m new on spoj..can anyone tell me I can check that on which test case my code is not accepted

kkislay20: 2018-03-08 12:55:47

Attention should be given that there could 1000000 digits in a number.

manos_l98: 2018-03-04 14:19:15

I write this program with c++ and I get abort error because I use stoull can someone tell me how to fix it?

pigpork: 2018-03-04 03:33:33

Can we use arrays?

ani_mahajan: 2018-02-28 20:06:24

Can someone tell me that what would be output if input > 1000000 .

zim_95: 2018-02-28 08:08:04

Same problem here..I get the correct answer on my code, still I get the wrong answer here, If only we could see what test case the code failed at, it would be great.

sharingancoder: 2018-02-18 07:28:23

can someone give some corner cases where code can go wrong

Last edit: 2018-02-18 08:11:07
adilmah: 2018-01-25 14:39:15

@quock The constraint is given on the number of digits

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 38%
Implementation difficulty
Implementation difficulty 49%
285 7