C++ || count_if and all_of || fast (100%, 36ms)
Solution 1: count_if with array\n\nThis is straighforward: a keeps track with characters are in allowed and then we just check each word against a.\n\ncpp\n    
### Solution 1: count_if with array<bool, 128>\n\nThis is straighforward: ```a``` keeps track with characters are in ```allowed``` and then we just check each word against ```a```.\n\n```cpp\n    static int countConsistentStrings(const string& allowed, const vector<string>& words) {\n        array<bool, 128> a = {};\n        for (char ch : allowed) a[ch] = true;\n        return count_if(begin(words), end(words), [&a](const string& word) {\n            for (char ch : word) {\n                if (!a[ch]) return false;\n            }\n            return true;\n        });\n    }\n```\n\nWe could also replace the raw for loop with ```all_of```:\n\n```\n    static int countConsistentStrings(const string& allowed, const vector<string>& words) {\n        array<bool, 128> a = {};\n        for (char ch : allowed) a[ch] = true;\n        return count_if(begin(words), end(words), [&a](const string& word) {\n            return all_of(begin(word), end(word), [&a](char ch) { return a[ch]; });\n        });\n    }\n```\n\nTo speed things up I have done a few things:\n  * update the function signature slightly:\n    * changed ```string allowed``` to ```const string& allowed``` to avoid a string copy\n    * using ```static```, this avoids a ```this``` pointer being passed into ```countConsistentStrings``` as this function doesn\'t use any member variables\n    * just for good measured made ```words``` const, because we are not modifying it.\n  * Using the following code to speed up IO at module scope:\n```\nstatic int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();\n```\n\n**Complexity Analysis**\n  * Time Complexity: O(n), where n is the number of total characters in the input, in the worst case we need to look at all strings.\n  * Space Complexity: O(1) only loop variables and a bool array of fixed size.\n\n _As always: Feedback is welcome and please upvote if you like this post._
['C']