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.
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026