Magicsheet logo

Reconstruct Original Digits from English

Medium
87.3%
Updated 6/1/2025

Reconstruct Original Digits from English

What is this problem about?

The Reconstruct Original Digits from English problem gives you a jumbled string containing letters from digit words (zero through nine). Reconstruct the digit counts and return them in sorted order as a string. This medium coding problem uses unique letter detection to identify digits in a specific order. The math, hash table, and string interview pattern is demonstrated.

Why is this asked in interviews?

Salesforce, Wix, and Google ask this because it tests systematic reasoning: some digits have unique letters that others don't. Once you extract those unique-letter digits, you can subtract their contributions and recover remaining digits. It rewards mathematical/linguistic pattern recognition.

Algorithmic pattern used

Unique letter extraction in specific order. Identify digits by their unique letters:

  • 'z' → 'zero'. 'w' → 'two'. 'u' → 'four'. 'x' → 'six'. 'g' → 'eight'.
  • 'o' (remaining after 0,2,4) → 'one'. 'h' (remaining after 8) → 'three'. 'f' (remaining after 4) → 'five'. 's' (remaining after 6) → 'seven'. 'i' (remaining after 5,6,8) → 'nine'. Count each, subtract letters, continue.

Example explanation

s="owoztneoer". Count: {o:2,w:1,z:1,t:1,n:1,e:2,r:1}.

  • 'z'=1 → one 'zero'. Subtract: o,z,e,r. Remaining: {o:1,w:1,t:1,n:1,e:1}.
  • 'w'=1 → one 'two'. Subtract: t,w,o. Remaining: {n:1,e:1}.
  • 'o'=0 → 0 'one'. 'e'=1... Process all → result sorted = "012".

Common mistakes candidates make

  • Processing digits in wrong order (must handle unique-letter digits before dependent ones).
  • Not subtracting letter contributions after counting each digit.
  • Confusing frequency of letter vs frequency of digit.
  • Off-by-one in the extraction sequence.

Interview preparation tip

Reconstruct Original Digits From English demonstrates "unique identifier extraction" — a systematic elimination approach. Identify the most uniquely-identifiable items first, subtract their contribution, then continue. This pattern applies to similar "reconstruct from partial information" problems. Memorize the 5 unique letters: z,w,u,x,g → 0,2,4,6,8.

Similar Questions