✔ [C++ / Python3] Solution | XOR
Complexity\n- Time complexity: O(n)\n- Space complexity: O(1)\n\n# Python3\n\nclass Solution:\n    def canConstruct(self, S, K):\n        return bin(reduce(oper
# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(1)$$\n\n# Python3\n```\nclass Solution:\n    def canConstruct(self, S, K):\n        return bin(reduce(operator.xor, map(lambda x: 1 << (ord(x) - 97), S))).count(\'1\') <= K <= len(S)\n```\n\n# C++\n```\nclass Solution {\npublic:\n    bool canConstruct(string s, int k) {\n        int val = 0;\n        for(char c: s) val ^= (1 << (c - \'a\'));\n        return k <= s.length() && __builtin_popcount(val) <= k;\n    }\n};\n```
['Bit Manipulation', 'Python3']