TopCoder problem "NextPalindromicNumber" used in SRM 330 (Division II Level Three)



Problem Statement

    

A palindromic number is a number that reads the same forward and backward. 101, 4 and 6666 are palindromic numbers while 10, 564 and 15452 are not.

You will be given a String n representing a positive integer. Determine the smallest palindromic integer strictly greater than n, and return it as a String with no leading zeroes.

 

Definition

    
Class:NextPalindromicNumber
Method:getNext
Parameters:String
Returns:String
Method signature:String getNext(String n)
(be sure your method is public)
    
 

Notes

-No positive multiple of 10 is a palindromic number.
 

Constraints

-n will contain between 1 and 50 characters, inclusive.
-Each character of n will be a digit ('0'-'9').
-The first character of n will not be zero ('0').
 

Examples

0)
    
"12345"
Returns: "12421"
1)
    
"858"
Returns: "868"
2)
    
"1999"
Returns: "2002"
3)
    
"1"
Returns: "2"
4)
    
"9999"
Returns: "10001"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7257

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10010&pm=7257

Writer:

soul-net

Testers:

PabloGilberto , brett1479 , Olexiy , misof

Problem categories:

Simple Math, String Manipulation