Problem

Largest Number With Digit Sum

Learn this problem
AmazonFULLTIMEOA
See Amazon hiring insights

Problem 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) → String

Examples

Example 1

x = 3y = 4n = 13return = "4333"

Some valid numbers are 3334, 3343, 3433, and 4333. The largest is 4333.

Constraints

  • 1 <= x, y <= 9
  • 1 <= n <= 10^6
  • At least one valid answer exists.

More Amazon problems

drafts saved locally
public String largestNumberWithDigitSum(int x, int y, int n) {
  // write your code here
}
x3
y4
n13
expected"4333"
checking account