Reconstruct Original Digits from English - Problem
Given a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order.
The string contains English words for digits like "zero", "one", "two", etc., but the letters are jumbled together. Your task is to figure out which digits are present and return them sorted.
Note: Each digit appears at most once in the input string.
Input & Output
Example 1 — Basic Mixed Digits
$
Input:
s = "owtzero"
›
Output:
"02"
💡 Note:
The string contains letters for "zero" (z,e,r,o) and "two" (t,w,o). Since we need ascending order, return "02".
Example 2 — Single Digit
$
Input:
s = "fviefuro"
›
Output:
"45"
💡 Note:
Contains "four" (f,o,u,r) and "five" (f,i,v,e). The shared 'f' appears twice. Result is "45".
Example 3 — Multiple Overlapping
$
Input:
s = "nnei"
›
Output:
"19"
💡 Note:
Contains "one" (o,n,e) and "nine" (n,i,n,e). Both share 'n' and 'e', but the counts work out perfectly for digits 1 and 9.
Constraints
- 1 ≤ s.length ≤ 105
- s consists of lowercase English letters only
- s contains an out-of-order representation of some digits 0-9
- Each digit appears at most once
Visualization
Tap to expand
Understanding the Visualization
1
Input
Scrambled letters from English digit words
2
Process
Use letter frequency analysis to identify digits
3
Output
Digits in ascending order
Key Takeaway
🎯 Key Insight: Use unique letters as fingerprints - some digits have letters that appear in no other digit word
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code