P21689 [GeeksforGeeks] 5c2734730cb1e98e3877a0b91f7d680d0efc8acf
普及
题目描述

The task is to find the second smallest number with a given sum of digits as S and the number of digits as D.
Example 1:
Input:
S = 9
D = 2
Output:
27
Explanation:
18 is the smallest number possible with sum = 9
and total digits = 2, Whereas the second
smallest is 27.
Example 2:
Input:
S = 16
D = 3
Output:
178
Explanation:
169 is the smallest number possible with sum is
16 and total digits = 3, Whereas the second
smallest is 178.
Your Task:
You don't need to read input or print anything. Your task is to complete the function secondSmallest() which takes the two integers S and D respectively and returns a string which is the second smallest number if possible, else return "-1".
Expected Time Complexity: O(D)
Expected Space Complexity: O(1)
Constraints:
1 ≤ S ≤ 10^{5}
1 ≤ D ≤ 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
S = 9 D = 2
样例输出
27