FastPrepReconstruct Digits from Jumbled English Words

Reconstruct Digits from Jumbled English Words

Microsoft logoMicrosoftMediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

A lowercase string is formed by concatenating zero or more English digit words (zero through nine) and arbitrarily shuffling all letters.

Return the original digits in ascending order. Repeated digit words are allowed. Return INVALID when the letters cannot be partitioned completely into digit words.

Function

reconstructEnglishDigits(letters: String) → String

Examples

Example 1

letters = "owoztneoer"return = "012"

The letters form zero, one, and two.

Example 2

letters = "fviefuro"return = "45"

The letters form four and five.

Example 3

letters = "abc"return = "INVALID"

The letters cannot be consumed by digit words.

Constraints

  • 0 <= letters.length <= 100000.
  • letters contains lowercase English letters.

More Microsoft problems

See Microsoft hiring insights
public String reconstructEnglishDigits(String letters) {
    // Write your solution here.
}
letters"owoztneoer"
expected"012"
Checking account…