Reconstruct Original Digits from English - Problem
You're given a jumbled string containing the English words for digits 0-9, but all mixed up! Your task is to figure out which digits were originally present and return them in ascending order.
For example, if you see "owzttnfour", this contains the letters for "two" and "four", so you should return "24".
The Challenge: Some letters appear in multiple digit words (like 'o' in both "zero" and "four"), so you need to be clever about how you count them!
Goal: Reconstruct the original digits from the scrambled English representation and return them sorted in ascending order as a string.
Input & Output
example_1.py โ Basic Case
$
Input:
s = "owzttnfour"
โบ
Output:
"24"
๐ก Note:
The string contains letters for "two" and "four". Since we return digits in ascending order, the answer is "24".
example_2.py โ Multiple Digits
$
Input:
s = "fviefuro"
โบ
Output:
"45"
๐ก Note:
The string contains letters for "four" and "five". Sorted in ascending order gives us "45".
example_3.py โ Single Digit
$
Input:
s = "nnei"
โบ
Output:
"9"
๐ก Note:
The string contains letters for "nine" only, so the answer is "9".
Constraints
- 1 โค s.length โค 105
- s[i] is a lowercase English letter
- s is guaranteed to be a valid representation of some digits 0-9
Visualization
Tap to expand
Understanding the Visualization
1
Gather Evidence
Count how many times each letter appears in the scrambled text
2
Find Smoking Guns
Look for unique letters: 'z' only appears in 'zero', 'w' only in 'two', etc.
3
Solve Easy Cases
Count digits with unique letters first - these are guaranteed wins
4
Deduce Harder Cases
Use the remaining letters to figure out the trickier digits
5
Present Evidence
Arrange your findings in ascending order to present the solution
Key Takeaway
๐ฏ Key Insight: Look for unique letters first (z, w, u, x, g), then systematically deduce remaining digits. This transforms a complex combinatorial problem into a simple counting and deduction exercise!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code