Skip to main content
Back to problems
Leetcode
Medium
Arrays
Strings
Hash Maps
Amazon
Word Subsets

Find all words in one list that are universal with respect to another list of words.

Acceptance 0%
Problem Statement

Problem

You are given two string arrays, words1 and words2.

A word a in words1 is called universal if, for every word b in words2, a contains all characters of b with at least the same multiplicity.

In other words, if a character appears k times in any word of words2, then every universal word in words1 must contain that character at least k times.

Return all universal words from words1.

Notes

  • Characters are lowercase English letters.
  • The answer can be returned in any order.

Input Format

Two arrays of lowercase strings:

  • words1: candidate words
  • words2: requirement words

Output Format

Return a list of all strings from words1 that satisfy the universal-word condition.

Constraints

Assume lowercase English letters only. The exact array sizes and word lengths follow the platform's original problem constraints.

Examples
Sample cases returned by the problem API.

Example 1

Input

words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["e","o"]

Output

["facebook","google","leetcode"]

Explanation

Each returned word contains at least one 'e' and at least one 'o'.

Example 2

Input

words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["l","e"]

Output

["apple","google","leetcode"]

Explanation

A universal word must contain at least one 'l' and one 'e'.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.