All questions

Integer to English Words

Premium

Integer to English Words

Spelling an integer in words turns a number like 1234567 into the phrase you would say out loud — One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven. You implement integerToEnglishWords(n), which takes a non-negative integer and returns its English name as capitalized words separated by single spaces. This is the LeetCode 273 problem, and the naming follows standard English numerals.

The catch is place value. English does not name digits one at a time — it groups them in threes (thousands, millions, billions), names each group of three, and glues on a scale word. Along the way it has special one-word names for the teens (Thirteen, not Ten Three) and joins tens and ones without a hyphen (Twenty One).

Signature

integerToEnglishWords(n: number): string
// n is an integer, 0 <= n <= 2_147_483_647

Examples

integerToEnglishWords(0);    // 'Zero'
integerToEnglishWords(21);   // 'Twenty One'
integerToEnglishWords(105);  // 'One Hundred Five'
integerToEnglishWords(1000); // 'One Thousand'
integerToEnglishWords(1234567);
// 'One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven'

integerToEnglishWords(1000005);
// 'One Million Five'   (the empty thousands group adds nothing)

Notes

  • Rangen is a non-negative integer up to 2147483647. That reaches the billions, so the scale words you need are Thousand, Million, and Billion.
  • ZerointegerToEnglishWords(0) returns 'Zero'. Zero is the only input where the word Zero appears; it never shows up inside a larger number.
  • No hyphens, no "and" — write Twenty One, not Twenty-One; write One Hundred Five, not One Hundred and Five. Every word is capitalized and separated by exactly one space.
  • Spacing — the result has no leading space, no trailing space, and no double spaces, even when a middle group of digits is all zeros (1000005 is One Million Five, with no gap where the thousands would go).
  • Teens are special13 is Thirteen, not Ten Three; the numbers 11 through 19 each have their own name.
  • What you can assumen is always a valid non-negative integer. You do not need to handle negative numbers, decimals, or strings.

FAQ

What are the time and space complexity?
Both are effectively constant. A 32-bit value has at most 10 digits, so there are at most four groups of three; each group is spelled in a fixed number of steps. The work grows with the number of digits, which is capped, and no extra space is used beyond the output string.
Why group the digits in threes instead of naming each digit?
English place value repeats every three digits — units, tens, hundreds within a group, then a scale word (thousand, million, billion) between groups. Naming one group of three and reusing that helper for every scale is what keeps the solution small and avoids special cases per magnitude.
How do you avoid a stray scale word like One Million Thousand Five?
Skip any group whose three digits are all zero. An empty group must contribute no words and no scale word, so 1,000,005 becomes One Million Five rather than One Million Thousand Five. The guard is a single continue on a zero group.

Unlock the solution & editor

  • Runnable editor + tests

    Solve in the browser with instant Jest feedback.

  • Detailed solutions

    Walkthroughs, edge cases, and complexity notes.

  • Multi-framework variants

    React, Vue, Vanilla, Angular — same question, different stacks.

Upgrade to Premium