Description
Given an array of strings words and a string chars, return the sum of lengths of all good words. A word is good if all characters can be formed using chars.
Examples
Input:
words = ["cat","bt","hat","tree"], chars = "atach"Output:
6Explanation:
cat and hat = 6.
Input:
words = ["hello","world","leetcode"], chars = "welldonehoneyr"Output:
10Explanation:
"hello" can be formed (h-1, e-1, l-2, o-1 all available) = 5 chars. "world" can be formed (w-1, o-1, r-1, l-1, d-1 all available) = 5 chars. "leetcode" cannot be formed (needs 3 e's but only 2 available). Total: 5 + 5 = 10.
Input:
words = ["a","aa","aaa"], chars = "aa"Output:
3Explanation:
"a" can be formed using 1 'a' = 1 char. "aa" can be formed using both 'a's = 2 chars. "aaa" cannot be formed (needs 3 'a's but only 2 available). Total: 1 + 2 = 3.
Constraints
- •
1 ≤ words.length ≤ 1000