Find all words in one list that are universal with respect to another list of words.
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 wordswords2: 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.
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.