TheInteger
SRM 437 · 2009-03-24 · by Vasyl[alphacom]
SRM 437 · 2009-03-24 · by Vasyl[alphacom] · Dynamic Programming
Problem Statement
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.
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
4)
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.
Coding Area
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