Integer to English Words

HardStringssimulation

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Convert a non-negative integer num into its English words representation. Use Title Case words separated by single spaces, with no leading or trailing spaces, no hyphens, and no "and". Group the number in threes using the scale words Thousand, Million, and Billion, and write each group with Hundred and the words for 1-19 and the tens (Twenty through Ninety). Omit any group that is zero. 0 is written as "Zero".

Examples

Input: num = 123
Output: "One Hundred Twenty Three"
One hundred, then twenty, then three.
Input: num = 12345
Output: "Twelve Thousand Three Hundred Forty Five"
The thousands group is 12, and the last group is 345.
Input: num = 1234567
Output: "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
Groups 1 / 234 / 567 with scales Million and Thousand.

Constraints

  • 0 <= num <= 2^31 - 1

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More simulation problems