You are given two positive integers num and sum. A positive integer n is good if it satisfies both of the following: - The number of digits in n is exactly num. - The sum of digits in n is exactly sum. The score of a good integer n is the sum of the squares of digits in n. Return a string denoting the good integer n that achieves the maximum score. If there are multiple possible integers, return the maximum one. If no such integer exists, return an empty string.
Example 1
Input: num = 2, sum = 3
Output: 30
Explanation: The good integers are 12, 21, and 30. Their scores are 5, 5, and 9, so 30 wins by concentrating the sum on one digit.
Example 2
Input: num = 2, sum = 17
Output: 98
Explanation: Both 89 and 98 score 145, the maximum. Since they tie, we return the larger number, 98.
Example 3
Input: num = 1, sum = 10
Output:
Explanation: A single digit can be at most 9, so no one-digit number has a digit sum of 10, and the answer is the empty string.
Squares grow fastest at the top, so to maximize the sum of squares you concentrate the digit sum onto as few digits as possible: use as many 9s as you can, one remainder digit, and zeros for the rest.
Run checks all cases above. Submit evaluates all test cases.