Convert number words to integer
Number Word to Integer Conversion
Problem Description
Given an English phrase representing a number, convert it to its corresponding integer value. The input number will be within the range of -999,999,999 to 999,999,999 (inclusive).
Supported Words
The conversion must handle the following English number words:
negative,zeroonethroughnineteentwenty,thirty,forty,fifty,sixty,seventy,eighty,ninetyhundred,thousand,million
Specific Rules
- Negative Numbers: Negative values are indicated by the word "negative" preceding the number phrase (e.g., "negative six hundred thirty eight").
- "Hundred" vs. "Thousand" Usage: The word "hundred" should not be used when "thousand" is applicable. For instance, 1500 should be parsed as "one thousand five hundred", not "fifteen hundred".
Output
For each input phrase, print its decimal integer representation.
Examples
- "fifteen" → 15
- "negative six hundred thirty eight" → -638
AI interview prep
Core dilemma
Accurately parsing a natural language string into a numerical value, handling specific grammatical rules and potential ambiguities, while ensuring correctness and extensibility.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Convert number words to integer
Number Word to Integer Conversion
Problem Description
Given an English phrase representing a number, convert it to its corresponding integer value. The input number will be within the range of -999,999,999 to 999,999,999 (inclusive).
Supported Words
The conversion must handle the following English number words:
negative,zeroonethroughnineteentwenty,thirty,forty,fifty,sixty,seventy,eighty,ninetyhundred,thousand,million
Specific Rules
- Negative Numbers: Negative values are indicated by the word "negative" preceding the number phrase (e.g., "negative six hundred thirty eight").
- "Hundred" vs. "Thousand" Usage: The word "hundred" should not be used when "thousand" is applicable. For instance, 1500 should be parsed as "one thousand five hundred", not "fifteen hundred".
Output
For each input phrase, print its decimal integer representation.
Examples
- "fifteen" → 15
- "negative six hundred thirty eight" → -638