TopcoderArchiveVisit Topcoder
SRM13 Dec 2006
SRM 330

NextPalindromicNumber

Problem statement, definition, constraints, and public examples.

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

  1. "12345"
    Returns: "12421"
  2. "858"
    Returns: "868"
  3. "1999"
    Returns: "2002"
  4. "1"
    Returns: "2"
  5. "9999"
    Returns: "10001"
Back to all problems