Magicsheet logo

Find Common Characters

Easy
100%
Updated 6/1/2025

Find Common Characters

What is this problem about?

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.

Why is this asked in interviews?

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.

Algorithmic pattern used

The problem uses Frequency Counting and Intersection.

  1. Initialize a global_counts array of size 26 with infinity (or frequencies from the first string).
  2. For each subsequent string in the input:
    • Calculate the character frequencies for that specific string.
    • For each character (a-z), update global_counts[i] = min(global_counts[i], current_string_counts[i]).
  3. After processing all strings, any character with a global_counts[i] > 0 is added to the result global_counts[i] times.

Example explanation

Strings: ["bella", "label", "roller"]

  1. First string "bella": {b:1, e:1, l:2, a:1}. Global = {a:1, b:1, e:1, l:2}.
  2. Second string "label": {l:2, a:1, b:1, e:1}. Intersect: {a:1, b:1, e:1, l:2}.
  3. Third string "roller": {r:2, o:1, l:2, e:1}. Intersect: {a:0, b:0, e:1, l:2}. Final result: ["e", "l", "l"].

Common mistakes candidates make

  • Ignoring duplicates: Only checking if a character exists in every string, rather than how many times it appears.
  • Inefficient map usage: Re-creating expensive objects instead of using a fixed-size integer array of length 26.
  • Complexity: Trying to compare all pairs of strings instead of maintaining a single running intersection.

Interview preparation tip

For lowercase English letter problems, an array int[26] is usually more efficient than a HashMap. It provides O(1)O(1) access and avoids the overhead of hashing, which is a detail interviewers appreciate.

Similar Questions