Largest Lucky Number With Digit Sum

Asked at Amazon · Coding Questions · Difficulty: Medium

A *lucky number* is a positive integer whose decimal digits are only `x` or `y` (two distinct digits). Given `x`, `y`, and a target digit sum `n`, return the largest lucky number whose digits sum to exactly `n`. It is guaranteed at least one exists.

Loading the problem…