2 Approaches✅✅|| Beats 100%🔥🔥 || Simple Explanation👌👌
The core of the problem is to fnd out if all the characters of each words string is present inside the allowed string.\n\nWe can either useset to store the allo
The core of the problem is to fnd out if ``all the characters of each words string is present inside the allowed string.``\n\nWe can either use`` set to store the allowed string characters or either we can directly use int arr (len(26)) to directly populate the specific character location of the allowed string.``\n\n## 1st method:(int arr[])\nTime_complexity:O((words.length*(lengthiest string in words).length)\nSpace complexity:O(26)\n\n**Mapping String in int array**\nIn this Approach we simply construct a int or **boolean array ,of length 26** and populate the location of each character in the order ``(A-0)->(Z-26)`` This can be achieved using ``(-\'a\')`` this will subtract 97 from its original value and return the ans;\n\n**Checking the Occurence of elements in the  int array**\nthus after storing the location of every letter in the arr we shall check in the words array whether every word string contains the characters from the characters mapped from the previous arr:\n\n``if yes count is incremented.\nif no count is not incremented.``\n\nAnd Hence the result is Obtained..\n\n# Code\n```java []\nclass Solution {\n    public int countConsistentStrings(String allowed, String[] words) {\n        int arr[]=new int[26];\n        for(char i:allowed.toCharArray()){\n            arr[i-\'a\']=1;\n        }\n        int count=0;\n        for(String k:words){\n            count+=findConsistentString(arr,k);\n        }\n        return count;\n    }\n    public static int findConsistentString(int arr[],String k){\n        int flag=1;\n        for(int i=0;i<k.length();i++){\n            if(arr[k.charAt(i)-\'a\']==0){\n                flag=0;\n                break;\n            }\n        }\n        return flag;\n    }\n}\n```\n``` C++ []\nclass Solution {\npublic:\n    int countConsistentStrings(string allowed, vector<string>& words) {\n        int arr[26] = {0};\n        for (char c : allowed) {\n            arr[c - \'a\'] = 1;\n        }\n        \n        int count = 0;\n        for (string word : words) {\n            int flag = 1;\n            for (char c : word) {\n                if (arr[c - \'a\'] == 0) {\n                    flag = 0;\n                    break;\n                }\n            }\n            count += flag;\n        }\n        return count;\n    }\n};\n\n```\n```python3 []\nclass Solution:\n    def countConsistentStrings(self, allowed: str, words: list[str]) -> int:\n        arr = [0] * 26\n        for c in allowed:\n            arr[ord(c) - ord(\'a\')] = 1\n        \n        count = 0\n        for word in words:\n            flag = 1\n            for char in word:\n                if arr[ord(char) - ord(\'a\')] == 0:\n                    flag = 0\n                    break\n            count += flag\n        return count\n\n```\n``` JavaScript []\nvar countConsistentStrings = function(allowed, words) {\n    let arr = new Array(26).fill(0);\n    for (let char of allowed) {\n        arr[char.charCodeAt(0) - \'a\'.charCodeAt(0)] = 1;\n    }\n    \n    let count = 0;\n    for (let word of words) {\n        let flag = 1;\n        for (let char of word) {\n            if (arr[char.charCodeAt(0) - \'a\'.charCodeAt(0)] === 0) {\n                flag = 0;\n                break;\n            }\n        }\n        count += flag;\n    }\n    return count;\n};\n\n```\n\n### 2nd Method:(HashSet)->Java\nIn this method we just have to repeat the above prcess but this time store it in a Hashset instead of an int array.\n\n# Code\n``` Java []\nclass Solution {\n    public int countConsistentStrings(String allowed, String[] words) {\n        Set<Character> set=new HashSet<>();\n        for(int i=0;i<allowed.length();i++){\n            set.add(allowed.charAt(i));\n        }\n        int count=0;\n        for(String k:words){\n            int flag=1;\n            for(int i=0;i<k.length();i++){\n                if(!set.contains(k.charAt(i))) {\n                    flag=0;\n                    break;\n                }\n            }\n            count+=flag;\n        }\n        return count;\n    }\n}\n```
['Array', 'Hash Table', 'C++', 'Java', 'Python3']