FastPrepFastPrep
Problem Brief

Max Lucky Numbers πŸ…

OA
See Amazon online assessment and hiring insights

Amazon.com is distributing coupons in the form of a lottery system for loyal customers. The coupons are called "lucky numbers" and the customer with the largest lucky number gets the best discount. Devise a method to determine the maximum possible lucky number. A positive integer is a lucky number if its decimal representation contains only digits x and y. For example, if x=2 and y=5, then 2, 552, and 5225 are lucky numbers, and 3, 24, 57 and 389 are not.

For example, if x=2 and y=5, then 2, 552, and 5225 are lucky numbers, and 3, 24, 57 and 389 are not.

Given two different digits x and y and a positive integer n, determine the maximum possible lucky number, the sum of whose digits is n. It is guaranteed that at least one lucky number exists for the given x, y, and n.

Function Description

Complete the function getMaxLuckyNumber in the editor.

getMaxLuckyNumber has the following parameters:

  1. x: an integer
  2. y: an integer
  3. n: the sum of the digits of the lucky number

Returns

int: the maximum possible lucky number

1Example 1

Input
x = 3, y = 4, n = 13
Output
4333
Explanation
If the two digits that make up the number are x = 3 and y = 4, and the sum of the digits must be n = 13, then the lucky numbers are:
  • 3334
  • 3343
  • 3433
  • 4333
  • The maximum lucky number is 4333.
    public int getMaxLuckyNumber(int x, int y, int n) {
        // write your code here
    }
    
    Input

    x

    3

    y

    4

    n

    13

    Output

    4333

    Sign in to submit your solution.