[Java/C++/Python] Straight Forward
Intuition\nCondition 1. odd characters <= k\nCount the occurrences of all characters.\nIf one character has odd times occurrences,\nthere must be at least one p
# **Intuition**\nCondition 1. `odd characters <= k`\nCount the occurrences of all characters.\nIf one character has odd times occurrences,\nthere must be at least one palindrome,\nwith odd length and this character in the middle.\nSo we count the characters that appear odd times,\nthe number of odd character should not be bigger than `k`.\n\nCondition 2. `k <= s.length()`\nAlso, if we have one character in each palindrome,\nwe will have at most `s.length()`  palindromes,\nso we need `k <= s.length()`.\n\nThe above two condition are necessary and sufficient conditions for this problem.\nSo we return `odd <= k <= n`\n<br>\n\n# **Construction**\n@spjparmar immediately got a question like why this works always for all strings.\nHe gave the some following dry runs. :)\nFor any string with 0 odd character count , we can form k no. of palindrome strings for sure with k<=n\n(This is why k<=n)\n\n**eg**\naabb, k=1| abba\naabb, k=2 | aa, bb\naabb, k=3 | a, a, bb\naabb, k=4 | a, a, b, b\n\nFor any string with odd character count <=k , we can always form k palindrome string for sure with k<=n\n**eg2**\naabbc, k=1 | aacbb\naabbc, k=2 | aca, bb\naabbc, k=3 | a,a, bcb\naabbc, k=4 | a, a, c ,bb\naabbc, k=5 | a, a, c, b, b\n\n**eg3**\naabc, k=1 | N/A\naabc, k=2 | aba, c\naabc, k=3 | aa, b, c\naabc, k=4 | a, a, b, c\n\nHope this helps somebody.\n<br>\n\n# **Complexity**\nTime `O(N)`\nSpace `O(1)`\n<br>\n\n**Java:**\n```java\n    public boolean canConstruct(String s, int k) {\n        int odd = 0, n = s.length(), count[] = new int[26];\n        for (int i = 0; i < n; ++i) {\n            count[s.charAt(i) - \'a\'] ^= 1;\n            odd += count[s.charAt(i) - \'a\'] > 0 ? 1 : -1;\n        }\n        return odd <= k && k <= n;\n    }\n```\n\n**C++:**\n```cpp\n    bool canConstruct(string s, int k) {\n        bitset<26> odd;\n        for (char& c : s)\n            odd.flip(c - \'a\');\n        return odd.count() <= k && k <= s.length();\n    }\n```\n\n**Python:**\n```py\n    def canConstruct(self, s, k):\n        return sum(i & 1 for i in collections.Counter(s).values()) <= k <= len(s)\n```
[]