shlogg · Early preview
Md Ariful Haque @mah-shamim

Counting Consistent Strings In PHP

Convert allowed string to set for O(1) lookups. Iterate through words, check each char in word against allowed set. Increment counter for consistent words.

1684. Count the Number of Consistent Strings
Difficulty: Easy
Topics: Array, Hash Table, String, Bit Manipulation, Counting
You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.
Return the number of consistent strings in the array words.
Example 1:

Input: allowed = "ab", words = ["ad","bd","aaab","baa","badab"]
Output: 2
Explanation: Strings "aaab" and "baa" are consistent since they only contain characters 'a' and 'b'.

Example 2:

Input: allowed = "abc", words = ["a...