The next code runs fine on my computer and does exactly what the problem states so why isn’t it accepted? it keeps telling me time limit exceeded but this runs in under half a second…
The problem is this:
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.
My code:
def Find_Smallest_Palindrome(Number):
Number = str(int(Number) + 1)
while Number != Number[::-1]:
Number = str(int(Number) + 1)
return Number
def Get_User_Input():
Number = input('')
return Number
print('Input: ')
Cycles = int(input(''))
x = 0
Numbers = []
while x < Cycles:
Number = int(input(''))
Numbers.append(Number)
x += 1
print()
print('Output: ')
for Number in Numbers:
print(Find_Smallest_Palindrome(str(Number)))
I do not know the exact formulation of the problem, but I think it is too slow for more complicated examples. Consider for instance the input
This will take very long with your code. I think, they test the given methods with such examples.