LARGEST PALINDROME
you are given an integer N . find the largest palindrome which is less than N .
INPUT
the input contains a single integer
OUTPUT
the output should be a single integer which is the largest palindrome that is less than the given input.
EXPLANATION
given N = 45
44 is the largest number which is a palindrome that is less than 45
SAMPLE INPUT 1
45
SAMPLE OUTPUT 1
44
SAMPLE INPUT 2
79
SAMPLE OUTPUT 2
77
N = int(input('Enter the number : '))
palindrome = -1
# 11 - smallest palindrome
for i in range(11, N):
if i > palindrome and str(i)[::-1] == str(i):
palindrome = i
if palindrome == -1:
print('No palindrome')
else:
print(palindrome)
Comments
Leave a comment