> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Reconstruct Original Digits from English

> Tested Python solution for LeetCode 423 with 22 pytest cases. Generate a practice environment with lcpy.

LeetCode 423, [Medium](/catalog/medium). Topics: [Hash Table](/catalog/topics/hash-table), [Math](/catalog/topics/math), [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/reconstruct-original-digits-from-english/description/).

Generate this problem as a practice environment: tested reference solution, 22 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 423   # by problem number
lcpy gen -s reconstruct_original_digits_from_english   # by problem name
```

## Problem

Given a string `s` containing an out-of-order English representation of digits `0-9`, return the digits in ascending order.

### Examples

```
Input: s = "owoztneoer"
Output: "012"
```

```
Input: s = "fviefuro"
Output: "45"
```

### Constraints

* 1 \<= s.length \<= 10^5
* s\[i] is one of the characters \["e","g","f","i","h","o","n","s","r","u","t","w","v","x","z"].
* s is guaranteed to be valid.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reconstruct_original_digits_from_english/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reconstruct_original_digits_from_english/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from collections import Counter


class Solution:
    # Time: O(n)
    # Space: O(1)
    def original_digits(self, s: str) -> str:
        counts: list[int] = [0] * 10
        c = Counter(s)
        # digits identified by a letter unique to their English word
        counts[0] = c["z"]
        counts[2] = c["w"]
        counts[4] = c["u"]
        counts[6] = c["x"]
        counts[8] = c["g"]
        # remaining digits by subtraction
        counts[1] = c["o"] - counts[0] - counts[2] - counts[4]
        counts[3] = c["h"] - counts[8]
        counts[5] = c["f"] - counts[4]
        counts[7] = c["s"] - counts[6]
        counts[9] = c["i"] - counts[5] - counts[6] - counts[8]
        return "".join(str(digit) * counts[digit] for digit in range(10))
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.