Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Find Words That Can Be Formed by Characters

XPChallenge Points: 10
levelLevel: Easy

You are given a list of words and a string chars which contains a set of available letters.
A word is considered valid if all of its characters can be created using the letters in chars, and each letter in chars can be used only as many times as it appears there.

Your task is to compute the total length of all words that can be completely formed using the characters from chars.

Example 1:

Input: words = ["map","app","spam","am"], chars = "apmsp"

Output: 5

Explanation:

"map" → can be made "app" → cannot (needs two 'p') "am" → can be made Total length = 3 + 2 = 5

Example 2:

Input: words = ["dog","good","go","odd"], chars = "odggo"

Output: 7

Explanation:

"dog" → valid "go" → valid "good" → not valid (needs two 'o' + two 'g', but only one 'g') "odd" → invalid Total length = 3 + 2 = 7

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result