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.
Input
The first line contains integer t, the number of test cases. Integers K are given in the next t lines.
Output
For each K, output the smallest palindrome larger than K.
What online compiler did you use and what was the input and output? When I run your program with the example input listed above I get the output listed above too so it seems to work at least for that case.
For a given positive integer K of not more than 1000000 digits
This means K can be up to 999999 digits long. You are reading the numbers into an array of long, which can store less than 25 digits.
Get the code working as it is for the sample input. Then switch to something different for the larger input.
You will find that for large numbers, your algorithm will be too slow. Imagine a 100 digit number: you won't be able to count up by ones to find the next palindrome. You may find that strings actually work better since you're really only concerned with the individual digits and not the value of the number as a whole.
As I hinted, I think you need to store the numbers as strings instead. Then the problem becomes figuring out how to create the proper palindrome of digits.