Easy Solution || All Languages
Intuition\nThe intuitive approach is to:\n\n1) Track the allowed characters.\n2) For each word in the words array, check whether all its characters are part of 
# Intuition\nThe intuitive approach is to:\n\n1) Track the allowed characters.\n2) For each word in the words array, check whether all its characters are part of the allowed characters.\n3) If any character in the word is not allowed, the word is inconsistent.\n\n# Approach\n1) HashSet for Allowed Characters:\nFirst, we store the characters of the allowed string in a HashSet, which allows for efficient lookup (average time complexity of O(1) for checking if a character is present).\nCheck Each Word:\n2) For each word in the words array, iterate through its characters. If any character in the word is not found in the HashSet, mark the word as inconsistent and reduce the total count.\nIf a word is consistent (i.e., all its characters are in the allowed set), we don\u2019t modify the count.\n\n# Complexity\n- Time complexity:\nO(k+n*m), where n is the numnber of word, m is the word of length, k is the length of allowed string\n\n- Space complexity:\nO(k) for hashset\n\n# Code\n```java []\nclass Solution {\n    public int countConsistentStrings(String allowed, String[] words) {\n        int count=words.length;\n\n        HashSet<Character> set=new HashSet<>();\n        for(char letter: allowed.toCharArray()){\n            set.add(letter);\n        }\n\n        for(String word: words){\n             for(int i=0;i<word.length();i++){\n                 if(!set.contains(word.charAt(i))){\n                    count--;\n                    break;\n                }\n             }\n        }\n        return count;\n    }\n}\n```\n``` C++ []\nclass Solution {\npublic:\n    int countConsistentStrings(std::string allowed, std::vector<std::string>& words) {\n        int count = words.size();\n        \n        // Create a set for allowed characters\n        std::unordered_set<char> set(allowed.begin(), allowed.end());\n\n        // Check each word for consistency\n        for (const std::string& word : words) {\n            for (char ch : word) {\n                if (set.find(ch) == set.end()) {\n                    count--;  // Reduce count if inconsistent\n                    break;\n                }\n            }\n        }\n\n        return count;\n    }\n};\n```\n```Python []\nclass Solution(object):\n    def countConsistentStrings(self, allowed, words):\n        """\n        :type allowed: str\n        :type words: List[str]\n        :rtype: int\n        """\n        count = len(words)\n\n        # Create a set of allowed characters\n        allowed_set = set(allowed)\n\n        # Check each word for consistency\n        for word in words:\n            for ch in word:\n                if ch not in allowed_set:\n                    count -= 1  # Reduce count if inconsistent\n                    break\n\n        return count\n\n```\n```Javascript []\n/**\n * @param {string} allowed\n * @param {string[]} words\n * @return {number}\n */\nvar countConsistentStrings = function(allowed, words) {\n    let count = words.length;\n\n    // Create a set of allowed characters\n    const allowedSet = new Set(allowed);\n\n    // Check each word for consistency\n    for (const word of words) {\n        for (const ch of word) {\n            if (!allowedSet.has(ch)) {\n                count--;  // Reduce count if inconsistent\n                break;\n            }\n        }\n    }\n\n    return count;\n};\n```\n![193730892e8675ebafc11519f6174bee5c4a5ab0.jpeg](https://assets.leetcode.com/users/images/2cf1d7bf-9218-4ffc-a89e-0c1bbef3ae89_1726111985.301947.jpeg)\n
['Array', 'Hash Table', 'Counting', 'C++', 'Java']