One Pager Cheat Sheet

  • You can convert a number to its text equivalent using number spelling in O(n) time and O(n) space complexity, where n is the number of digits and the number of digits must not exceed 100.
  • We can convert the number 123 to a string type to start our operation.
  • We need to define units, tens and scales for building the final string, and then divide the number into chunks of 3 digits to account for different scales.
  • We iterate through num in O(n) linear time, and convert it to a string of length n for O(n) space complexity.

This is our final solution.

To visualize the solution and step through the below code, click Visualize the Solution on the right-side menu or the VISUALIZE button in Interactive Mode.

JAVASCRIPT

Great job getting through this. Let's move on.

If you had any problems with this tutorial, check out the main forum thread here.