#34Warehouse Label Assembly Validator
A warehouse uses a character inventory to prepare labels for outgoing packages. The system receives a list of requested package labels and a collection of characters currently available in the warehouse. You are given: packageLabels — an array of strings representing the labels that need to be prepared. availableChars — a string containing the characters currently available for creating labels.
A package label is assembleable if every character required by that label appears in availableChars with sufficient frequency. The available characters can be reused independently for each package label. In other words, checking one label does not consume characters needed to check another label. Return the sum of the lengths of all assembleable package labels.
Important Rules Character frequency matters. A character can be used only as many times as it appears in availableChars for a single label. Characters used for one label are restored before checking the next label. All characters consist of lowercase English letters.
Real-World Applications: Automated Package Label Printing Inventory-Based Label Generation Automated Sorting and Packaging
Examples
Example 1
Input: packageLabels = ["box","bag","tag","crate"]
availableChars = "abctgox"
Output: 9
Explanation: "box" → can be assembled → length 3 "bag" → can be assembled → length 3 "crate" → cannot be assembled "tag" → can be assembled → length 3 Total: 3 + 3 + 3 = 9 Correction: "bag" requires b,a,g, all available; "tag" requires t,a,g, all available. Therefore the correct output is: 9
Example 2
Input: packageLabels = ["label","box","pack","crate"]
availableChars = "abelxopk"
Output: 3
Explanation: --
Example 3
Input: packageLabels = ["aaa","bbb","ccc"]
availableChars = "abc"
Output: 0
Constraints
- 1 <= packageLabels.length <= 1000
- 1 <= packageLabels[i].length <= 100
- 1 <= availableChars.length <= 100
- packageLabels[i] contains only lowercase English letters.
- availableChars contains only lowercase English letters.
- The same availableChars inventory can be used independently for every label.
- A label must use characters in exactly the required frequencies.
