Practice/Amazon/Leetcode 273. Integer to English Words
CodingMust
Write a function that converts a non-negative integer into its English word representation. For example, the number 123 should become "One Hundred Twenty Three". Your solution needs to handle numbers from 0 up to 2,147,483,647 (the maximum value for a 32-bit signed integer).
The key challenge is to properly group digits into chunks representing different magnitudes (billions, millions, thousands, and ones), convert each chunk into words, and combine them with the appropriate scale words.
Example 1:
Input: num = 123 Output: "One Hundred Twenty Three" Explanation: The number has a hundreds place (1), tens place (2), and ones place (3)
Example 2:
Input: num = 12345 Output: "Twelve Thousand Three Hundred Forty Five" Explanation: Split into 12 (thousands) and 345 (ones). 12 becomes "Twelve Thousand" and 345 becomes "Three Hundred Forty Five"
Example 3:
Input: num = 1000000 Output: "One Million" Explanation: Exactly one million with no other components
Example 4:
Input: num = 0 Output: "Zero" Explanation: Zero is a special case