Weekly Programming Challenge 1: Next Palindrome
Weekly Programming Challenge 1: Next Palindrome
Next Palindrome
Definition : An integer is a palindrome if it has the same value even after reversing all
its digits.
Examples :
14541, 33, 9870789 are palindromes but 23, 933, 89989 are not palindromes.
Design a JAVA program which, for a positive integer n, computes the smallest integer
greater than n which is a palindrome. Your program should run efficiently for arbitrarily
large value of n. More specifically, declare n as variable of type long, for any arbitrarily
large value of n, your program should take at most a few seconds (in fact millisecond if
possible).
For example :
for n = 1234501234, the output should be 1234554321. for n = 325986, the output should
be 326623.
A naive approach to solve the problem would be the following :