Integer to English Words

Convert a non-negative integer `num` to its English words representation, for example `12345` becomes `"Twelve Thousand Three Hundred Forty Five"`. Words are capitalised and separated by single spaces, with no "and" and no hyphens.

30:00

Integer to English Words
hard
Free written solution
Topics
Companies

Convert a non-negative integer num to its English words representation, for example 12345 becomes "Twelve Thousand Three Hundred Forty Five". Words are capitalised and separated by single spaces, with no "and" and no hyphens.

Example 1:
Input: {"num":123}
Output: One Hundred Twenty Three
Constraints:
  • 0≤num≤231−10 \leq \text{num} \leq 2^{31} - 1

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"num":123}

num = 123

split into groups

1
2
3

units

num left in the loop

123

Read 123 in groups of three digits, as you would with commas: each group is a number below 1000 followed by a scale word.

words so far (each group prepends its words)

empty

Variables
VariableValue
num123
DepthFunction Call
Stack empty
0/8