Connection Status:
Competition Arena > NextPalindromicNumber
SRM 330 · 2006-12-13 · by soul-net · Simple Math, String Manipulation
Class Name: NextPalindromicNumber
Return Type: String
Method Name: getNext
Arg Types: (string)
Problem Statement

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.

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"

Submissions are judged against all 128 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class NextPalindromicNumber with a public method string getNext(string n) · 128 test cases · 2 s / 256 MB per case

Submitting as anonymous