Count Words Formable from Letters
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) → intExamples
Example 1
text = "Hello, hole! world."letters = "helloo"return = 2Hello and hole are formable; world requires unavailable letters.
Example 2
text = "Cat dog"letters = "tac"return = 1Cat is formable case-insensitively, while dog is not.
Constraints
0 <= text.length,letters.length <= 100000