💥 C# | Runtime beats 96.32%, Memory beats 93.68% [EXPLAINED]
\n\n\n# Intuition\nI realized I could represent the allowed characters and each word using a bitmask. This way, instead of checking characters one by one, I can
![image.png](https://assets.leetcode.com/users/images/f1a2b4f3-8de5-4f9b-a976-8b64a84299b2_1726118612.997129.png)\n\n\n# Intuition\nI realized I could represent the allowed characters and each word using a bitmask. This way, instead of checking characters one by one, I can quickly compare them using bitwise operations.\n\n# Approach\nConvert the allowed string into a bitmask, where each bit represents a character.\n\nFor each word, create its bitmask.\n\nIf the word\u2019s bitmask fits within the allowed bitmask, count it as consistent.\n\n# Complexity\n- Time complexity:\nO(n * m) \u2013 I process each word and its characters once.\n\n- Space complexity:\nO(1) \u2013 I only use a fixed 26-bit bitmask.\n\n# Code\n```csharp []\npublic class Solution {\n    public int CountConsistentStrings(string allowed, string[] words) {\n        // Bitmask to represent allowed characters\n        int allowedMask = 0;\n        foreach (var ch in allowed) {\n            allowedMask |= (1 << (ch - \'a\'));\n        }\n\n        int count = 0;\n\n        foreach (var word in words) {\n            int wordMask = 0;\n            foreach (var ch in word) {\n                wordMask |= (1 << (ch - \'a\'));\n            }\n\n            // If the word\'s mask is a subset of allowedMask, it\'s consistent\n            if ((wordMask & allowedMask) == wordMask) {\n                count++;\n            }\n        }\n\n        return count;\n    }\n}\n\n```
['C#']