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
lunaticgaming: 2019-02-15 04:44:10

Execution Time: .04
My solution worked for all cases that I tested, but it failed in their test.
My solution finally passed on this site when I removed the leading zeros of the input.

deep123r: 2019-02-14 17:14:15

Check for these things
1. Check for Corner Cases(i.e. -all digits are 9 only) ,eg for 99,999,9999,99999(for these just add 2 to the numbers)
2. Leading Zeroes are no problem,e.g. for 000001=001100 is acceptable and 2 is also acceptable.

mighty_joe781: 2019-02-12 07:42:13

I am also getting TLE any ideas.

randm_codr_rs: 2019-02-05 14:15:20

I'm getting runtime error NZEC in this problem while submitting
but perfectly running on ideone platform

venom_black: 2019-01-18 14:37:29

too hard

gjenkinsedu: 2019-01-17 23:43:55

I have written a C version that passes with all test data on SPOJToolkit, and I have hand tested it with numbers of more than 10000 digits and it works fine. but It still fails on SPOJ with wrong results. Any suggestions or places with more extensive test cases

ashwini_571: 2019-01-15 21:26:34

Last edit: 2019-01-15 21:26:56
squirrelli: 2019-01-03 14:02:41

If input is 010,000, isn't the output 10,001?

sehgal_divij: 2019-01-02 13:21:19

runs on my machine but fails here.
note that I am using -std=c++11 flag while compiling on my device. It works on my device but fails with the following error here:

runtime error(SIGABRT)

Works on ideone

Suggestions on what to do?

Link to working version on ideone:

Last edit: 2019-01-02 13:41:01
nitin_uniyal: 2018-12-23 05:14:36

running time 0.56 s.
Don't convert the string to int or long int anywhere. Strip the input to remove '\n'. Use the list of string characters because strings are immutable in nature. Characters
Consider all cases e.g.
'0', '9',' 99', '1991' etc.

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 49%
339 9