Problem
Largest Number With Digit Sum
Learn this problemProblem statement
You are given three integers x, y, and n, where x and y are digits from 1 to 9.
Construct the largest possible decimal number whose digits are only x and y, and whose digit sum is exactly n.
It is guaranteed that at least one valid number exists.
Function
largestNumberWithDigitSum(x: int, y: int, n: int) → StringExamples
Example 1
x = 3y = 4n = 13return = "4333"Some valid numbers are 3334, 3343, 3433, and 4333. The largest is 4333.
Constraints
1 <= x, y <= 91 <= n <= 10^6- At least one valid answer exists.