Count the Number of Consistent Strings

Easy

Description

Given a string allowed and an array of strings words, return the number of consistent strings. A string is consistent if all characters appear in allowed.

Examples

Input:allowed = "ab", words = ["ad","bd","aaab","baa","badab"]
Output:2
Explanation:

Only aaab and baa are consistent.

Input:allowed = "cad", words = ["cc","acd","b","ba","bac","bad","ac","d"]
Output:4
Explanation:

Checking each word: "cc" (valid), "acd" (valid), "b" (invalid - 'b' not allowed), "ba" (invalid), "bac" (invalid), "bad" (invalid), "ac" (valid), "d" (valid). 4 strings are consistent.

Input:allowed = "xyz", words = ["x","y","z","xy","xz","yz","xyz","xyza"]
Output:7
Explanation:

All words are consistent except "xyza" because it contains 'a' which is not in the allowed string "xyz". The first 7 words only use combinations of the allowed characters 'x', 'y', and 'z'.

Constraints

  • 1 ≤ words.length ≤ 10^4

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!