One day ninja is assigned a task by his teacher to write the numbers âNâ into their word form. So he started writing the number into their word form but it takes a lot of time so he comes up with the idea of writing a code which can convert the given numbers into their word form.
So help our ninja write a code that can convert a number into its word form.
So your task is to write a code that can convert numbers into their word form.
For example :You have given a number â1234â so you have to convert it in its word form that is â0ne thousand two hundred thirty fourâ.
Note :
You do not need to print anything; it has already been taken care of. Just implement the function
The first line of input contains the âTâ number of test cases.
The first line of each test case contains an integer âNâ.
Output Format :
For each test case, return its word form in the string.
1 <= T <= 100000
1 <= N <= 999998
Time Limit: 1 second
2
9923
523
nine thousand nine hundred twenty three
five hundred twenty three
Test Case 1 :
In the first line, there is the number of test cases i.e., 1, and in the next lineâ9923âis
The integer which we have to convert into a word form.
Here, we have started with dividing the number into individual digits and writing in its word form.
String s= ânine thousandâ + ânine hundredâ + âtwenty threeâ.
Test case 2 :
String s= âfive hundredâ + âtwenty threeâ.
2
89
8989
eighty nine
eight thousand nine hundred eighty nine
Try to divide the number into individual digits
We divide our numbers into individual digits and operate on them starting from the most significant digit.
O(1)
We are performing a constant number of operations therefore the time complexity is O(1).
O(1)
We are using a constant amount of space therefore the space complexity is O(1).