TheInteger
SRM 437 · 2009-03-24 · by Vasyl[alphacom]
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.
Constraints
- n will be between 1 and 10^18, inclusive.
- k will be between 1 and 10, inclusive.
Statement by TopCoder, Inc. — view the original on the archive.
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.
7 3 Returns: 102
We need three distinct digits here.
69 2 Returns: 69
69 already consists of two different digits.
12364 3 Returns: 12411
91 1 Returns: 99
Submissions are judged against all 128 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TheInteger with a public method long long find(long long n, int k) · 128 test cases · 2 s / 256 MB per case