Maximize Sum of Squares of Digits
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
nis exactlynum. - The sum of digits in
nis exactlysum.
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 = 3Output
"30"Among the good integers 12, 21, and 30, 30 has the maximum score of 9.
Example 2
Input
num = 2, sum = 17Output
"98"Both 89 and 98 have the maximum score of 145, and 98 is the maximum such good integer.
Constraints
- 1 <= num <= 2 * 10^5
- 1 <= sum <= 2 * 10^6