Integer to English Words - Problem

Transform any non-negative integer into its English words representation - just like how you would read the number aloud!

Given an integer like 123, you need to convert it to "One Hundred Twenty Three". This problem tests your ability to handle complex string manipulation, number parsing, and recursive thinking.

Key Challenge: Handle the unique patterns in English number naming - like "Eleven" vs "Ten One", "Twenty" vs "Two Ten", and the complex grouping system (thousands, millions, billions).

Examples:

  • 123 → "One Hundred Twenty Three"
  • 12345 → "Twelve Thousand Three Hundred Forty Five"
  • 1234567 → "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"

Input & Output

example_1.py — Basic Three Digits
$ Input: 123
Output: "One Hundred Twenty Three"
💡 Note: Break down: 123 = 100 + 20 + 3. Convert to English: "One Hundred" + "Twenty" + "Three"
example_2.py — Thousands with Teens
$ Input: 12345
Output: "Twelve Thousand Three Hundred Forty Five"
💡 Note: Groups: [12][345]. Process: "Twelve Thousand" + "Three Hundred Forty Five". Note how 12 becomes "Twelve" (not "Ten Two")
example_3.py — Edge Case Zero
$ Input: 0
Output: "Zero"
💡 Note: Special case: the only time we return "Zero" as the complete answer

Constraints

  • 0 ≤ num ≤ 231 - 1
  • No leading/trailing spaces in the output
  • Words are separated by single spaces
  • No "and" conjunctions (American English style)

Visualization

Tap to expand
📢 News Anchor Number Reading SystemInput: 1,234,567 → "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"Breaking down like a professional broadcaster📚 Lookup TablesOnes: One, Two...Teens: Eleven, Twelve...Tens: Twenty, Thirty...Scale: Thousand, Million✂️ Group by 3s1,234,567→ [1] [234] [567]Million | Thousand | OnesRight to Left processing🔧 Helper FunctionProcess each group:567 → Five Hundred+ Sixty SevenHandle 11-19 specially🏷️ Add ScalesGroup 0: (no suffix)Group 1: + "Thousand"Group 2: + "Million"Group 3: + "Billion"🎬 Step-by-Step Conversion Process:1. Group 567: helper(567) → "Five Hundred Sixty Seven"2. Group 234: helper(234) + " Thousand" → "Two Hundred Thirty Four Thousand"3. Group 1: helper(1) + " Million" → "One Million"4. Combine: ["One Million", "Two Hundred Thirty Four Thousand", "Five Hundred Sixty Seven"]5. Result: "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"✅ Perfect English pronunciation achieved!Time: O(log n) | Space: O(1) | Handles all edge cases including teens and zeros
Understanding the Visualization
1
Create Lookup Tables
Build comprehensive tables for ones (0-19), tens (20-90), and scales (thousand, million, billion)
2
Group by Thousands
Break the number into 3-digit groups from right to left (ones, thousands, millions, etc.)
3
Process Each Group
Convert each 3-digit group using helper function that handles hundreds, tens, and ones
4
Add Scale Suffixes
Append appropriate scale words (Thousand, Million, Billion) to non-zero groups
5
Combine and Clean
Join all parts from largest to smallest scale with proper spacing
Key Takeaway
🎯 Key Insight: English numbers follow a systematic 3-digit grouping pattern with consistent internal rules, making lookup tables and recursive processing the optimal approach.
Asked in
Google 42 Microsoft 38 Amazon 31 Meta 24
67.2K Views
Medium-High Frequency
~25 min Avg. Time
1.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen