Skip to content

916. Word Subsets #1114

Answered by mah-shamim
mah-shamim asked this question in Q&A
Jan 10, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

We need to identify the words in words1 that are "universal", meaning each string in words2 is a subset of the word from words1.

Approach:

  1. Count the Frequency of Characters in words2:

    • First, we need to determine the maximum count for each character across all strings in words2. This gives us the required number of occurrences for each character to be a subset.
  2. Check Each Word in words1:

    • For each word in words1, count the frequency of each character.
    • If the character counts in the word from words1 meet or exceed the required counts from words2, then the word is universal.
  3. Return the Universal Words:

    • After checking all words in words1, return the ones that are universal.

Let's…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Jan 10, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants