[Java/Python 3] 2 codes: Bit manipulation and 1 liners w/ brief explanation and analysis.
Q & A\n\nQ1: What is alphabet for in method 1?\n\nA1: alphabet stores the information whether an alphabet is allowed or not in an efficient way. Normally we can
**Q & A**\n\nQ1: What is `alphabet` for in method 1?\n\nA1: `alphabet` stores the **information** whether an **alphabet** is allowed or not in an efficient way. Normally we can create a `Boolean` array of `26` and mark the allowed alphabets `true` if present and `false` otherwise. Because alphabet is of type `int` it has `32` bits and we need `26`(think Why?) so ,a single `int` will be enough instead of an `array` to deduce whether an **alphabet** is allowed or not.\n\nNow how to store **information**:\nYou see initially `alphabet` is `0`. Its binary form is `00000........`\nNow we **set** the `LSB`(Least Significant Bit) to `1` to represent that a is allowed. `........00001` => means only `a` is allowed\nSimilarly we **set** the **second last bit** to `1` to represent that `b` is allowed. `......000010` => means only `b` is allowed\n`......0000011` => this means `a` and `b` are both allowed\nIf an **alphabet** is not allowed we **skip** it. (it remains `0`)\nLet\'s take an example `allowed = "acdg"`\n`alphabet` initially is `0(...00000)`\nfor `a` it will become `...00001`\nthen for `c ...00101`\nfor `d ....001101`\nat last for `g .....001001101`\n\n-- Credit to **@KenpachiZaraki1**\'s excellent explanation.\n\n**End of Q & A**\n\n----\n\n**Method 1: Bit manipulation**\n1. Use the bits of an int to indicate the characters in `allowed`.\n2. Loop through the `words` and check if all the characters of each word present in the `allowed`; if yes, count it in; otherwise ignore it.\n```java\n    public int countConsistentStrings(String allowed, String[] words) {\n        int alphabet = 0, cnt = 0;\n        for (int i = 0; i < allowed.length(); ++i) {\n            int shift = allowed.charAt(i) - \'a\';\n            alphabet |= 1 << shift;\n        } \n        outer:\n        for (String w : words) {\n            for (int i = 0; i < w.length(); ++i) {\n                if ((alphabet & (1 << w.charAt(i) - \'a\')) == 0) {\n                    continue outer;\n                }\n            }\n            ++cnt;\n        }\n        return cnt;\n    }\n```\n```python\n    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n        alphabet = sum(1 << ord(c) - ord(\'a\') for c in allowed)\n        return sum(all((alphabet & (1 << ord(c) - ord(\'a\')) != 0 \\\n                        for c in word))  \\\n                        for word in words)\n```\n\n----\n\n**Method 2:1 liners**\n\n```java\n    public int countConsistentStrings(String allowed, String[] words) {\n        return Arrays.stream(words)\n                     .mapToInt(w -> w.chars().allMatch(c -> allowed.contains((char)c + "")) ? 1 : 0)\n                     .sum();\n    }\n```\nIn case you are not comfortable with Java Stream, here are variants:\n```java\n    public int countConsistentStrings(String allowed, String[] words) {\n        int cnt = 0;\n        outer:\n        for (String w : words) {\n            for (int i = 0; i < w.length(); ++i) {\n                if (!(allowed.contains(w.charAt(i) + ""))) {\n                    continue outer;\n                }\n            }\n            ++cnt;\n        }\n        return cnt;       \n    }\n```\n```java\n    public int countConsistentStrings(String allowed, String[] words) {\n        var seen = new HashSet<Character>();\n        for (char c : allowed.toCharArray()) {\n            seen.add(c);\n        } \n        int cnt = 0;\n        outer:\n        for (String w : words) {\n            for (char c : w.toCharArray()) {\n                if (!seen.contains(c)) {\n                    continue outer;\n                }\n            }\n            ++cnt;\n        }\n        return cnt;\n    }\n```\n\n```python\n    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n        return sum(all(c in allowed for c in word) for word in words)\n```\n**Analysis:**\nTime: O(n), space: O(1), where n = the total characters in `words` and `allowed`.\t\t\t\t\t\t
[]