Given a string array words, return all characters that show up in every string in words, including duplicates. If a character appears at least 3 times in every string but not at least 4 times in every string, include that character exactly three times in the answer.
Function Signature
def common_chars(words: list[str]) -> list[str]:
...
Rules
-
Each element of the result is a one-character string.
-
Return the characters sorted in alphabetical order, so repeated characters sit next to each other.
-
Return an empty list when no character appears in every word.
Constraints
-
1 <= len(words) <= 100
-
1 <= len(words[i]) <= 100
-
words[i]
consists of lowercase English letters.
Examples
Input: words = ["bella","label","roller"]
Output: ["e","l","l"]
Every word has at least one "e" and at least two "l" characters. "b" and "a" are missing from "roller", and "r" and "o" are missing from the other two words.
Input: words = ["cool","lock","cook"]
Output: ["c","o"]
"c" appears once in each word. "o" appears twice in "cool" and "cook" but only once in "lock", so it is included once. "l" is missing from "cook".
Input: words = ["abc","def"]
Output: []
The two words share no letters.