EquiDigitNumbers
SRM 392 · 2008-03-06 · by darnley
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.
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.
"42" Returns: 42
When given an equidigit number, you should return that same number.
"2008" Returns: 2013
The numbers 2008, 2009, 2010, 2011 and 2012 are not equidigit, and the number 2013 is.
"987654322" Returns: 987778899
"1000000000000000000" Returns: 1111111111111111111
The number 1111111111111111111 is equidigit, so the answer always fits into a 64-bit signed integer.
"1" Returns: 1
Submissions are judged against all 90 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class EquiDigitNumbers with a public method long long findNext(string n) · 90 test cases · 2 s / 256 MB per case