Find all characters that appear in every string of the input array, including duplicates by the minimum shared frequency.
Given an array of lowercase strings, return the characters that appear in every string. If a character appears multiple times in every string, include it that many times in the result.
The result can be returned in any order.
This problem is about tracking the minimum frequency of each character across all strings and collecting the shared characters at the end.
Input Format
- An array of strings
words - Each string contains only lowercase English letters
Output Format
- Return an array of strings/characters containing the common characters across all input strings
- Duplicate characters should appear according to their minimum shared count
Constraints
1 <= words.length- Each word contains only lowercase English letters
- A character may appear multiple times in the answer if it appears multiple times in every string
Example 1
Input
words = ["bella","label","roller"]
Output
["e","l","l"]
Explanation
The character e appears in all three words once. The character l appears in all three words at least twice, so it is included twice.
Example 2
Input
words = ["cool","lock","cook"]
Output
["c","o"]
Explanation
c appears once in every word, and o appears once in every word. No other character is common to all three strings.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.