Use Bitmaksing And OR Operation To Count Consistent Strings | Java | C++ | [Video Solution]
Intuition, approach, and complexity discussed in video solution in detail\nhttps://youtu.be/3b_ESeRgDqA\n\n# Code\njava []\nclass Solution {\n    public int cou
# Intuition, approach, and complexity discussed in video solution in detail\nhttps://youtu.be/3b_ESeRgDqA\n\n# Code\n``` java []\nclass Solution {\n    public int countConsistentStrings(String allowed, String[] words) {\n        int allowedMask = maskString(allowed);\n        int consistStrCnt = 0;\n        for(var word : words){\n            int wordMask = maskString(word);\n            if((wordMask | allowedMask) == allowedMask)consistStrCnt++; \n        }\n        return consistStrCnt;\n    }\n    private int maskString(String str){\n        int strMask = 0;\n        for(char ch : str.toCharArray()){\n            int relPos = (ch - \'a\');\n            strMask |= (1<<relPos);\n        }\n        return strMask;\n    }\n}\n```\n```cpp []\nclass Solution {\npublic:\n    int countConsistentStrings(string allowed, vector<string>& words) {\n        int allowedMask = maskString(allowed);\n        int consistStrCnt = 0;\n        for(auto & word : words){\n            int wordMask = maskString(word);\n            if((wordMask | allowedMask) == allowedMask)consistStrCnt++; \n        }\n        return consistStrCnt;\n    }\nprivate:\n    int maskString(string str){\n        int strMask = 0;\n        for(auto & ch : str){\n            int relPos = (ch - \'a\');\n            strMask |= (1<<relPos);\n        }\n        return strMask;\n    }\n\n};\n```
['Array', 'String', 'Bit Manipulation', 'Counting', 'C++', 'Java']