✅||Easy solutions||[with proof]||Beats 100% in most||🔥|🐍|C#️⃣|C➕➕|☕|💎|🔥🔥
HELLOW PLEZ UPVOTE!!

Intuition💡
A palindrome is a string that reads the same forward and backward.
For constructing a palindrome:

Characters must appear in
- # ***********************HELLOW PLEZ UPVOTE!!***********************
![beats 100% .png](https://assets.leetcode.com/users/images/2927a2ed-c3e0-4221-af75-b6c3ca14ac2d_1736581868.0719783.png)


# Intuition💡
- A palindrome is a string that reads the same forward and backward.
- For constructing a palindrome:
1. Characters must appear in pairs (even frequency).
1. At most one character with an odd frequency can be placed at the center of the palindrome.
- The challenge is to determine if it's possible to create exactly `k` palindromes from the string `s`.

---


# Approach🚀
1. First check if k is larger than string length - if yes, return false
1. Count frequency of each character using an array of size 26
1. Count total number of characters with odd frequencies
1. Return true if odd count ≤ k and k ≤ string length

---


# Complexity
# 1. Time Complexity 🕒
O(n): Iterate through the string to update the bitmask.
# 2. Space Complexity 🗄️
O(1): Constant space for the bitmask.

---


---


---
*****THESE ARE VERY SMALL AND EASY CODES!*****
# Code
```cpp []
class Solution {
public:
    bool canConstruct(string s, int k) {
        if (s.length() < k) return false;

        sort(s.begin(), s.end());
        int oddCount = 0;

        for (int i = 0; i < s.length(); ) {
            char current = s[i];
            int count = 0;
            while (i < s.length() && s[i] == current) {
                count++;
                i++;
            }
            if (count % 2 != 0) oddCount++;
        }

        return oddCount <= k;
    }
};
```

```java []
class Solution {
    public boolean canConstruct(String s, int k) {
        if (s.length() < k)
            return false;
        if (s.length() == k)
            return true;

        int odd = 0;

        for (char chr : s.toCharArray())
            odd ^= 1 << (chr - 'a');

        return Integer.bitCount(odd) <= k;
    }
}
```

```python []
class Solution:
    def canConstruct(self, s: str, k: int) -> bool:
        if len(s) < k:
            return False
        if len(s) == k:
            return True

        odd = 0

        for chr in s:
            odd ^= (1 << (ord(chr) - ord('a')))

        return bin(odd).count('1') <= k
```

```javascript []
class Solution {
    canConstruct(s, k) {
        if (k > s.length) return false;
        const charCount = new Array(26).fill(0);
        for (let c of s) {
            charCount[c.charCodeAt(0) - 'a'.charCodeAt(0)]++;
        }
        let oddCount = 0;
        for (let i = 0; i < 26; i++) {
            if (charCount[i] % 2 === 1) oddCount++;
        }
        return oddCount <= k && k <= s.length;
    }
}
```

```ruby []
def can_construct(s, k)
    return false if s.length < k

    chars = s.chars.sort
    odd_count = 0

    i = 0
    while i < chars.length
        current = chars[i]
        count = 0
        while i < chars.length && chars[i] == current
            count += 1
            i += 1
        end
        odd_count += 1 if count.odd?
    end

    odd_count <= k
end
```

```C# []
using System;

public class Solution {
    public bool CanConstruct(string s, int k) {
        if (s.Length < k) return false;

        char[] chars = s.ToCharArray();
        Array.Sort(chars);
        int oddCount = 0;

        for (int i = 0; i < chars.Length; ) {
            char current = chars[i];
            int count = 0;
            while (i < chars.Length && chars[i] == current) {
                count++;
                i++;
            }
            if (count % 2 != 0) oddCount++;
        }

        return oddCount <= k;
    }
}
```

```c []
bool canConstruct(char* s, int k) {
    int freq[256] = {0};
    int single_count = 0;
    
    for (int i = 0; s[i] != '\0'; i++) {
        freq[s[i]]++;
    }

    for (int i = 0; i < 256; i++) {
        if (freq[i] % 2 == 1) {
            single_count++;
        }
    }

    return single_count <= k && k <= strlen(s);
}
```
![image.png](https://assets.leetcode.com/users/images/eeaff577-80b5-4196-98da-780a75ca8dd7_1736581852.2488704.png)





['C', 'Python', 'C++', 'Java', 'Ruby', 'JavaScript', 'C#']