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.
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
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
Accepted:
Submission: