Find Common Characters - Problem
Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.
For example, if a character occurs 3 times in each string and 2 times in another string, you should include that character 2 times in the final answer (the minimum occurrence across all strings).
Input & Output
Example 1 — Basic Case
$
Input:
words = ["bella","label","roller"]
›
Output:
["e","l","l"]
💡 Note:
Character 'e' appears once in each word, 'l' appears twice in each word, so result is ["e", "l", "l"]
Example 2 — Different Frequencies
$
Input:
words = ["cool","lock","cook"]
›
Output:
["c","o"]
💡 Note:
Character 'c' appears once in each word, 'o' appears twice in 'cool' and 'cook' but once in 'lock', so we take minimum count of 1
Example 3 — No Common Characters
$
Input:
words = ["abc","def","ghi"]
›
Output:
[]
💡 Note:
No characters appear in all three words, so result is empty array
Constraints
- 1 ≤ words.length ≤ 100
- 1 ≤ words[i].length ≤ 100
- words[i] consists of lowercase English letters.
Visualization
Tap to expand
Understanding the Visualization
1
Input Analysis
Array of strings with various characters
2
Find Common
Identify characters present in every string
3
Minimum Count
Take minimum frequency across all strings
Key Takeaway
🎯 Key Insight: The result is limited by whichever string has the fewest occurrences of each character
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code