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
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.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code