![]() |
VOOZH | about |
Given a number, print words for individual digits. It is not allowed to use if or switch.
Examples:
Input: n = 123 Output: One Two Three Input: n = 350 Output: Three Five Zero
We strongly recommend you to minimize your browser and try this yourself first.
The idea is to use an array of strings to store digit to word mappings. Below are steps.
Let the input number be n.
Below is the implementation of the above idea.
three five zero
Time Complexity: O(|n|), where |n| is the number of digits in the given number n.
Auxiliary Space: O(1), to store digit to word mapping
Thanks to Utkarsh Trivedi for suggesting above solution.