Integer to English Words: Up to 20 Digits
Updated
Problem statement
Convert the integer represented by the decimal string number into English words. The number can have up to 20 digits, excluding a minus sign. Do not try to store the whole input in a signed 64-bit integer.
For this exercise, assume the input may start with a minus sign and may contain leading zeros. Use the international scales Thousand, Million, Billion, Trillion, Quadrillion and Quintillion. Capitalize each word, separate words with one space, and use no hyphens or the word and. If the number is negative and not zero, begin the result with Negative. Any input whose value is zero returns Zero.
Function
numberToWords(number: String) → StringExamples
Example 1
number = "12345"return = "Twelve Thousand Three Hundred Forty Five"Split the magnitude into groups 12 and 345, attach Thousand to the first group and spell each nonzero group.
Example 2
number = "10000000000000000001"return = "Ten Quintillion One"The leading 20-digit group means ten quintillion. Skip the zero-valued intervening groups.
Constraints
- For this exercise, assume the input matches an optional minus sign followed by 1 through 20 decimal digits.
- The absolute value is at most
99999999999999999999. - The input contains no whitespace or other characters.
More PeopleStrong Onsite Interview questions
- Add Two Binary StringsONSITE INTERVIEW · Seen Mar 2026
- Four SumONSITE INTERVIEW · Seen Mar 2026
- LRU Cache OperationsONSITE INTERVIEW · Seen Mar 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Mar 2026
- Find the Entry of a Linked List CycleONSITE INTERVIEW · Seen Sep 2025
- Word Ladder II: All Shortest TransformationsONSITE INTERVIEW · Seen Sep 2025
- Detect a Cycle in a Linked ListONSITE INTERVIEW · Seen May 2025
- First Nonrepeating CharacterONSITE INTERVIEW · Seen May 2025
- Longest Subarray with a Target SumONSITE INTERVIEW · Seen May 2025
- Lowest Common Ancestor in a BSTONSITE INTERVIEW · Seen May 2025
Similar questions at other companies
- Every Result of Grouping an ExpressionC3.ai · ONSITE INTERVIEWC3.ai interview questions
- Basic CalculatorAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Nested JSON Schema ValidatorPinterest · ONSITE INTERVIEWPinterest interview questions
- Toy Language Generic Return-Type InferenceOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Transform L/R Pieces on a Circular BoardGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Validate Nested JSON Against a SchemaBenchling · ONSITE INTERVIEWBenchling interview questions
- Evaluate an Arithmetic Expression with DivisionMotive · ONSITE INTERVIEWMotive interview questions
- Validate a Nested Object Against a SchemaConfluent · ONSITE INTERVIEWConfluent interview questions
- Nearest Palindromic NumberApple · ONSITE INTERVIEWApple interview questions
- Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions