Total Length of Independently Formable Words. For each word in words, determine whether its letters can be taken from chars, using each occurrence in chars at most once for that word.
### Problem
For each word in words, determine whether its letters can be taken from chars, using each occurrence in chars at most once for that word. Reset the available letters for the next word. Return the sum of lengths of all formable input words.
```cpp
class Solution {
public:
int countCharacters(vector<string>& words, string chars);
};
```
### Examples
**Example 1:**
```text
Input: words = ["ab","aa","ba"], chars = "aab"
Output: 6
Explanation: Each word separately fits the available two a letters and one b, contributing2 each.
```
**Example 2:**
```text
Input: words = ["zz","z","zzz"], chars = "zz"
Output: 3
Explanation: zz and z fit; zzz requires an unavailable third z.
```
### Constraints
- There are 1 to 1000 words.
- Each word and chars has length 1 to 100.
- All characters are lowercase English letters.
### Contract considerations
Characters may be rearranged to form a word; their positions in chars impose no order.
```hint Read the boundary condition
Are letters consumed across different words, or is the supply restored for each input entry?
```
### Boundary reminders
Characters may be rearranged to form a word; their positions in chars impose no order.
Overview: Total Length of Independently Formable Words. For each word in words, determine whether its letters can be taken from chars, using each occurrence in chars at most once for that word.
For each word in words, determine whether its letters can be taken from chars, using each occurrence in chars at most once for that word. Reset the available letters for the next word. Return the sum of lengths of all formable input words.
class Solution {
public:
int countCharacters(vector<string>& words, string chars);
};
Examples
Example 1:
Input: words = ["ab","aa","ba"], chars = "aab"
Output: 6
Explanation: Each word separately fits the available two a letters and one b, contributing2 each.
Example 2:
Input: words = ["zz","z","zzz"], chars = "zz"
Output: 3
Explanation: zz and z fit; zzz requires an unavailable third z.
Constraints
There are 1 to 1000 words.
Each word and chars has length 1 to 100.
All characters are lowercase English letters.
Contract considerations
Characters may be rearranged to form a word; their positions in chars impose no order.
Boundary reminders
Characters may be rearranged to form a word; their positions in chars impose no order.