Advertisement blocking software were detected ;( Please add this webpage to whitelist.

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
vigneshkv: 2015-11-22 19:08:21

<Beginner feedback>
<c++ 5>
I took almost 1week for this problem.if you get TLE or Signal 11 error,there is a mistake in your implementation.try optimizing the code ,reduce the number of loops.
if you get signal 11 error ,there is a problem in some initialisation.
i used two dimensional array which caused TLE.i can say single dimensional array is better.
reducce the loops for not letting it getting stuck in TLE.

Last edit: 2015-11-22 19:09:45
miki_24: 2015-11-18 15:58:05

why "time limit exceeded"? my code works perfectly on my computer and in
This inputs 11
236723867238967289367283967289, 238967238672837628937628937629731346716241386972409682365107365, 2587238597238461876343285468034689347616347826369850960347628364234293840, 745847583745, 3458349573485729865 etc are solved in 0,03 sec , I'm writing in python 3.5, when submitting choosing Python 3.4 . Can't get what's wrong
please help

Last edit: 2015-11-18 16:02:38
Dushyant Singh: 2015-11-15 17:27:21

For those who are getting WA even after confirming all test cases use cin instead of fflush and scanf. I just changed that in my code even without looking at it(which was months old) and got AC. scanf is a mess for strings and char arrays.

Last edit: 2015-11-15 17:29:57
rc_alex36: 2015-11-15 16:25:27

Confirmed that there are nothing wrong with the test cases. If u get a WA then there's some problem with ur code. I literally used an hour to debug just to reach an Accepted. Try 999, 8997, 3, 9, 100, 1000, 9999 beforehand.

Priyank: 2015-11-12 11:58:38

First make a simple ago. (just for handling int) then make it more sophisticated for handling large numbers.

Last edit: 2015-11-12 11:59:10
nonstatic: 2015-11-09 08:01:11

@abhi_269, go try "999999999999".

gj21: 2015-11-04 05:58:28


LeppyR64: 2015-11-03 15:15:10

FYI: Almost everyone that posts on the forum for this problem skips exactly one word in this problem statement.

Last edit: 2015-11-03 15:15:31
vsp4: 2015-10-27 14:02:50

Very nice adhoc problem :) Got AC in first submission here but after many debugging. Had to generate a bruteforce solution of 1 to 10000 numbers and then match with my approach to find corner cases.

layman806: 2015-10-25 20:59:17

Hahaha, accepted on the first go!! Love the problem!

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

Problem's scores 1 vote

Concept difficulty
Concept difficulty 42%
Implementation difficulty
Implementation difficulty 46%
83 3