Skip to content

1684. Count the Number of Consistent Strings #530

Discussion options

You must be logged in to vote

The idea is to check if each word in the words array is consistent with the characters in the allowed string. A word is consistent if all its characters are present in the allowed string.

Plan

  1. Allowed Characters Set:

    • We can convert the allowed string into a set of characters to efficiently check if each character in the word exists in the set.
  2. Word Consistency Check:

    • For each word in the words array, check if all its characters exist in the allowed set.
  3. Count Consistent Words:

    • Initialize a counter. For each word that is consistent, increment the counter.
  4. Return the Count:

    • Once all words are processed, return the count of consistent words.

Let's implement this solution in…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mah-shamim
Comment options

mah-shamim Sep 12, 2024
Maintainer Author

@basharul-siddike
Comment options

Answer selected by mah-shamim
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 easy Difficulty
2 participants