Ctrl K

Digits From Scrambled Words

Medium
Some digits were written out as English words (zero, one, …, nine), the words were glued into one string, and then all the letters were shuffled. The result is the string letters. Recover the original digits and return them as a string in ascending order. Digits may repeat. The string is guaranteed to have been produced this way.
Example 1
letters="rotwheet" → '23'

The letters spell two and three, so the answer is "23".

Example 2
letters="eninorez" → '09'

Only zero has a z; what remains spells nine. The answer is "09".

Example 3
letters="vesenxsiixs" → '667'
Constraints
  • 1 ≤ len(letters) ≤ 10⁵
  • letters only contains the letters e g h i f o n s r u t w v x z
  • letters is a shuffle of English digit names
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNumber in Roman Numerals MediumFraction as a Decimal MediumPieces With Matching Ends MediumMessages Behind Key Presses MediumPieces With a Fixed Zero-to-One Ratio Medium
loading Python…
Input
letters="rotwheet"
Expected
'23'

Run checks the first 3 tests in your browser. Submit checks all 168 tests on the server, hidden ones included.