Trains the technique from
LeetCode 273Integer to English WordsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A payments desk prints vouchers, and each voucher carries its amount spelled out in words beside the figures. Given a non-negative integer amount, return the words the printer should put on the voucher.
The printer's vocabulary is fixed. Single figures and teens: 1 One, 2 Two, 3 Three, 4 Four, 5 Five, 6 Six, 7 Seven, 8 Eight, 9 Nine, 10 Ten, 11 Eleven, 12 Twelve, 13 Thirteen, 14 Fourteen, 15 Fifteen, 16 Sixteen, 17 Seventeen, 18 Eighteen, 19 Nineteen. Whole tens: 20 Twenty, 30 Thirty, 40 Forty, 50 Fifty, 60 Sixty, 70 Seventy, 80 Eighty, 90 Ninety. It also holds the words Hundred, Thousand, Million, Billion and Zero.
The printer works to these rules.
amount of 0 prints as Zero. For every other amount the word Zero is never printed.Billion, Million, Thousand, and the rightmost group carries no tag.0 prints nothing whatsoever, tag included.Hundred when that digit is not 0; then the number formed by its last two digits, as one word when that number is 1 through 19, as the whole-tens word plus the units word when the units digit is not 0, as the whole-tens word by itself when the units digit is 0, and as nothing at all when both digits are 0. The group's tag comes last.and, and no space at either end of the answer.Example 1
There is one group, 907. Its hundreds digit is 9, which prints Nine Hundred, and its last two digits form 7, which prints Seven.
Example 2
The groups are 6, 042 and 519, tagged Million, Thousand and nothing. They print Six Million, then Forty Two Thousand, then Five Hundred Nineteen.
Example 3
The groups are 5, 000 and 018. The middle group is all zeros, so it prints nothing and its Thousand tag goes with it, leaving Five Million Eighteen.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def spell_amount(amount: int) -> str:public String spellAmount(int amount)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.