In the Find Common Characters interview question, you are given an array of strings. You need to return a list of all characters that appear in every string in the array, including duplicates. For example, if "l" appears three times in every string, your result must include "l" three times.
This "Easy" difficulty question is popular at Microsoft and Meta to test a candidate's mastery of Hash Table interview patterns and frequency counting. It evaluation whether you can efficiently "intersect" multiple frequency maps. It’s a test of whether you can maintain a "global minimum frequency" for each character across a set of inputs.
The problem uses Frequency Counting and Intersection.
global_counts array of size 26 with infinity (or frequencies from the first string).global_counts[i] = min(global_counts[i], current_string_counts[i]).global_counts[i] > 0 is added to the result global_counts[i] times.Strings: ["bella", "label", "roller"]
{b:1, e:1, l:2, a:1}. Global = {a:1, b:1, e:1, l:2}.{l:2, a:1, b:1, e:1}. Intersect: {a:1, b:1, e:1, l:2}.{r:2, o:1, l:2, e:1}. Intersect: {a:0, b:0, e:1, l:2}.
Final result: ["e", "l", "l"].For lowercase English letter problems, an array int[26] is usually more efficient than a HashMap. It provides access and avoids the overhead of hashing, which is a detail interviewers appreciate.