TopCoder problem "TheInteger" used in SRM 437 (Division I Level Two)



Problem Statement

    

There is nothing more beautiful than just an integer number.

You are given an integer n. Return the smallest integer greater than or equal to n that contains exactly k distinct digits in decimal notation.

 

Definition

    
Class:TheInteger
Method:find
Parameters:long, int
Returns:long
Method signature:long find(long n, int k)
(be sure your method is public)
    
 

Constraints

-n will be between 1 and 10^18, inclusive.
-k will be between 1 and 10, inclusive.
 

Examples

0)
    
47
1
Returns: 55
Here, k is 1, so we're looking for a number whose digits are all equal. The smallest such number that is greater than or equal to 47 is 55.
1)
    
7
3
Returns: 102
We need three distinct digits here.
2)
    
69
2
Returns: 69
69 already consists of two different digits.
3)
    
12364
3
Returns: 12411

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13699&pm=10231

Writer:

Vasyl[alphacom]

Testers:

PabloGilberto , bmerry , ivan_metelsky

Problem categories:

Dynamic Programming