Return the Multiset of Characters Present in Every Word

Quick Overview

Return the Multiset of Characters Present in Every Word. Return an array of one-character strings for all characters common to every word in words, including repeated occurrences.

Return the Multiset of Characters Present in Every Word

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return an array of one-character strings for all characters common to every word in `words`, including repeated occurrences. A character appears as many times as its smallest count in any input word. Return the characters in any order. ```cpp class Solution { public: vector<string> commonChars(vector<string>& words); }; ``` ### Examples **Example 1:** ```text Input: words = ["aabb","ababa","baa"] Output: ["a","a","b"] Explanation: Every word contains at least two a characters and at least one b; baa prevents a second common b. ``` **Example 2:** ```text Input: words = ["abc","def"] Output: [] Explanation: No character occurs in both words. ``` ### Constraints - `1 <= words.length <= 100`. - `1 <= words[i].length <= 100`. - Words contain only lowercase English letters. ### Contract considerations The returned elements are strings of length one, preserving the original `vector<string>` interface. ```hint Read the boundary condition For each letter, what is the most copies that every word can supply? ``` ### What a Strong Answer Covers The returned elements are strings of length one, preserving the original `vector<string>` interface. ### Follow-up Questions Optional practice extension, separate from the original task: How could you support strings arriving one at a time?

Overview: Return the Multiset of Characters Present in Every Word. Return an array of one-character strings for all characters common to every word in words, including repeated occurrences.

Amazon logo
Amazon
Jun 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return an array of one-character strings for all characters common to every word in words, including repeated occurrences. A character appears as many times as its smallest count in any input word. Return the characters in any order.

class Solution {
public:
    vector<string> commonChars(vector<string>& words);
};

Examples

Example 1:

Input: words = ["aabb","ababa","baa"]
Output: ["a","a","b"]
Explanation: Every word contains at least two a characters and at least one b; baa prevents a second common b.

Example 2:

Input: words = ["abc","def"]
Output: []
Explanation: No character occurs in both words.

Constraints

  • 1 <= words.length <= 100 .
  • 1 <= words[i].length <= 100 .
  • Words contain only lowercase English letters.

Contract considerations

The returned elements are strings of length one, preserving the original vector<string> interface.

What a Strong Answer Covers Guidance

The returned elements are strings of length one, preserving the original vector<string> interface.

Follow-up Questions Guidance

Optional practice extension, separate from the original task: How could you support strings arriving one at a time?