Ctrl K

Amount in Words

Hard
A bank prints the amount on its cheques in English words. Given a non-negative integer amount, return it written out in words. Formatting rules: - every word is capitalized and words are separated by exactly one space, with no hyphens or commas; - the word And is never used: 105 → "One Hundred Five"; - the scale words are Thousand, Million and Billion; any group equal to zero is skipped; - zero is written as "Zero". Vocabulary: One to Nineteen (Eleven, Twelve, Thirteen, Fourteen, Fifteen, Sixteen, Seventeen, Eighteen, Nineteen), the tens Ten, Twenty, Thirty, Forty, Fifty, Sixty, Seventy, Eighty, Ninety, and Hundred.
Example 1
amount=508 → 'Five Hundred Eight'

Five hundreds and an eight, with no "and" and nothing for the zero tens: "Five Hundred Eight".

Example 2
amount=40015 → 'Forty Thousand Fifteen'

40 thousand and 15: "Forty Thousand Fifteen".

Example 3
amount=2000300001 → 'Two Billion Three Hundred Thousand One'
Constraints
  • 0 ≤ amount ≤ 2³¹ − 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPlus-Minus Calculator With Brackets HardSimplify a Letter Polynomial HardCalculator With Brackets and Four Operations HardEvery Bracketing Result MediumPattern With Dot and Star Hard
loading Python…
Input
amount=508
Expected
'Five Hundred Eight'

Run checks the first 3 tests in your browser. Submit checks all 73 tests on the server, hidden ones included.