TopcoderArchiveVisit Topcoder
SRM6 Mar 2008
SRM 392

EquiDigitNumbers

Problem statement, definition, constraints, and public examples.

Problem Statement

A number x is called equidigit if each digit that appears in the decimal notation of x appears the same number of times. (x must be written with no leading zeroes.)

For example, the numbers 5, 239, 333888 and 566353 are equidigit.

Given a string representing a number n, return the smallest equidigit number that is greater than or equal to n.

Definition

Class:
EquiDigitNumbers
Method:
findNext
Parameters:
String
Returns:
long
Method signature:
long findNext(String n)
(be sure your method is public)

Notes

  • The answer always fits into a 64-bit signed integer.

Constraints

  • n will contain only digits, and will represent an integer between 1 and 10^18, inclusive, with no leading zeros.

Examples

  1. "42"
    Returns: 42
    When given an equidigit number, you should return that same number.
  2. "2008"
    Returns: 2013
    The numbers 2008, 2009, 2010, 2011 and 2012 are not equidigit, and the number 2013 is.
  3. "987654322"
    Returns: 987778899
  4. "12345678910"
    Returns: 22222222222
Back to all problems