TopCoder problem "EquiDigitNumbers" used in SRM 392 (Division I Level Three)



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

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

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=11126&pm=8536

Writer:

darnley

Testers:

PabloGilberto , Olexiy , ivan_metelsky , ged

Problem categories:

Search, Simple Math