Given a string, return the spelled-out English word for every digit it contains, separated by single spaces. Characters that are not digits are ignored.

If the input is null or contains no digits, return an empty string.

Examples:

Input: digits = '3072' Output: 'three zero seven two' Explanation: Each digit is replaced by its English word in order Input: digits = '9' Output: 'nine' Explanation: A single digit produces a single word Input: digits = 'a1b2' Output: 'one two' Explanation: The letters are skipped and only the digits are spelled out Input: digits = 'abc' Output: '' Explanation: There are no digits so the result is an empty string Input: digits = null Output: '' Explanation: A null input produces an empty string
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay November 2026 (Nov 16–30)Sponsored by FLXBL

Contest runs November 16 - 30. Complete challenges to climb the leaderboard!

Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes

Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In