You are given an Integer ‘N’ you have to convert the integer to words.
For example you are given integer N = 2234 then you have to return the string “two thousand two hundred and thirty four”.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next ‘T’ lines represent the ‘T’ test cases.
The first line of each test case contains a single integer N denoting the integer.
Output format :
For each test case, print a string representing the integer in words.
Note :
You don’t have to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N <= 999999999
Time Limit: 1 sec
3
1234
45821
555093
one thousand two hundred and thirty four
forty five thousand eight hundred and twenty one
five lakh fifty five thousand and ninety three
For the first test case:
The given integer is 1234 we can see that in words it is represented as “one thousand two hundred and thirty four”.
For the second test case:
The given integer is 45821; we can see that in words it is represented as “forty five thousand eight hundred and twenty-one”.
For the third test case
The given integer is 555093; we can see that in words it is represented as “five lakh fifty five thousand and ninety three”.
3
99999
1000
30000
ninety nine thousand nine hundred and ninety nine
one thousand
thirty thousand
Try to think about the words how you will store phrases.
The idea is to iterate through the number check for the place value of each digit and starting from the extreme left, we will check by dividing the number by place value integer like crore by 10000000 and similarly by other values.
O(1).
As the process happens only once so constant time will be taken.
O(1).
As we are using constant space.