Given an integer number ‘num’. Your task is to convert ‘num’ into a word.
Suppose the given number ‘num’ is ‘9823’ then you have to return a string “nine thousand eight hundred twenty three” that is word conversion of the given ‘num’ 9823.
The first line of input contains an integer ‘T’ denoting the number of test cases.
Each of the next ‘T’ lines contains a single integer ‘num’.
Output Format :
For each test case, return a string/character array that is the word form of the given number ‘num’.
Note :
1. In every two consecutive words, there must be a space.
2. All the characters of the word must be English lower letter.
3. The return type must be a string.
4. You are not required to print the output explicitly, it has already been taken care of. Just implement the function and return the word.
1 <= T <= 10^5
0 <= N <= 9999
Time limit: 1 sec
2
8743
649
eight thousand seven hundred forty three
six hundred forty nine
Test Case 1:
Given ‘num’ is ‘8743’
‘8743’ can be written as ‘ 8 x 1000 + 7 x 100 + 4 x 10 + 3’ and the word form of this number is “eight thousand seven hundred forty three”.
Test Case 2:
Given ‘num’ is ‘649’
‘649’ can be written as ‘ 6 x 100 + 4 x 10 + 9 ’ and the word form of this number is “six hundred forty nine”.
2
10
123
ten
one hundred twenty three
Try to think recursive.
O(1),
We are using at max ‘4’ step-depth recursion.
O(1),
We are using constant space.