Reconstruct Original Digits from English

MediumStringshashing

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A string of digits was converted to English words ("zero", "one", ..., "nine"), the words were concatenated, and then all the letters were shuffled. You are given the shuffled string s. Recover the digits and return them as a string sorted in ascending order (for example "012"). The input is guaranteed to be a valid shuffle of the words for some multiset of digits, and that multiset is uniquely determined.

Examples

Input: s = "owoztneoer"
Output: "012"
The letters are exactly those of "zero", "one" and "two".
Input: s = "fviefuro"
Output: "45"
The letters are exactly those of "four" and "five".

Constraints

  • 1 <= s.length <= 10^5
  • `s` consists only of letters from the English digit words
  • `s` is guaranteed to be valid

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More hashing problems