You get a list of words and a string chars. A word is good if it can be built from chars, using each character at most once per word. Return the total length of all good words.
Count chars once into 26 slots. For each word, count its letters and check that no slot exceeds the budget. Because the budget is reused for every word, never mutate the original counts.
from collections import Counter
def countCharacters(words, chars):
have = Counter(chars)
total = 0
for w in words:
need = Counter(w)
if all(have[ch] >= k for ch, k in need.items()):
total += len(w)
return total
Time is O(total letters across words plus len(chars)). Extra space is O(1) since the alphabet is fixed at 26.
Practising how you narrate these frequency-count checks helps a lot in live rounds; an AI interview assistant like Linkjob AI can give you that practice (disclosure: I work on Linkjob AI).