Loading content...
You are given a collection of candidate words and a character pool represented as a string. A word is considered constructible if it can be completely spelled out using only the characters available in the character pool, where each character in the pool can be used at most once per word.
For each word in the collection, the character pool is "refreshed" — meaning you have access to the full pool of characters again for each word evaluation. In other words, the same character pool is independently applied to test each word.
Your task is to determine the total length of all constructible words. Return the sum of the lengths of every word that can be successfully constructed from the character pool.
words = ["cat","bt","hat","tree"]
chars = "atach"6The character pool "atach" contains: 'a' (×2), 't' (×1), 'c' (×1), 'h' (×1). The word "cat" needs 'c', 'a', 't' — all available, so it's constructible (length 3). The word "bt" needs 'b', but 'b' is not in the pool — not constructible. The word "hat" needs 'h', 'a', 't' — all available, so it's constructible (length 3). The word "tree" needs 't', 'r', 'e', 'e', but 'r' and 'e' are not in the pool — not constructible. Total length of constructible words: 3 + 3 = 6.
words = ["hello","world","leetcode"]
chars = "welldonehoneyr"10The character pool "welldonehoneyr" contains sufficient characters to construct "hello" (needs h, e, l, l, o — all present with required counts) and "world" (needs w, o, r, l, d — all present). However, "leetcode" requires three 'e's and the pool only has two, plus it needs a 'c' which is absent. Thus, "hello" (length 5) and "world" (length 5) are constructible. Total: 5 + 5 = 10.
words = ["a","ab","abc"]
chars = "aabbcc"6The character pool "aabbcc" contains: 'a' (×2), 'b' (×2), 'c' (×2). All three words can be constructed: "a" uses one 'a', "ab" uses one 'a' and one 'b', "abc" uses one 'a', one 'b', and one 'c'. Since each word is evaluated independently against the full pool, all words are constructible. Total length: 1 + 2 + 3 = 6.
Constraints