FastPrepCount Words Formable from Letters

Count Words Formable from Letters

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

Problem statement

Split text into maximal English-letter words, ignoring punctuation. Count how many words can be formed from the case-insensitive letter multiset letters, using each supplied occurrence at most once per word.

Function

countFormableWords(text: String, letters: String) → int

Examples

Example 1

text = "Hello, hole! world."letters = "helloo"return = 2

Hello and hole are formable; world requires unavailable letters.

Example 2

text = "Cat dog"letters = "tac"return = 1

Cat is formable case-insensitively, while dog is not.

Constraints

  • 0 <= text.length,letters.length <= 100000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int countFormableWords(String text, String letters) {
    // Write your code here.
}
text"Hello, hole! world."
letters"helloo"
expected2
Checking account…