FastPrepLargest Number With Digit Sum
Problems/Largest Number With Digit Sum

Largest Number With Digit Sum

Amazon logoAmazonFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

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 Online Assessment questions

  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Nov 2026

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public String largestNumberWithDigitSum(int x, int y, int n) {
      // write your code here
    }
}
Checking account…