🌟 HashMap & Counting Made Simple! 🔢 | Beginner-Friendly 🐣 | O(N) Solution 🚀
Intuition : 💡We aim to split the string s into exactly k palindromic substrings.
Palindromes need at most 1 odd-frequency character 🔑.
Count odd-frequency chara
# Intuition : 💡
We aim to split the `string` `s` into exactly `k` palindromic substrings.

- Palindromes need `at most 1 odd-frequency` character 🔑.
- Count odd-frequency characters . If there are more odd characters than `k`, it’s impossible to form `k` palindromes.

---



# Approach 🔍
1. ***Edge Check***: If s.size() < k ➡️ return false 🙅‍♂️ (not enough characters to form k substrings).
2. ***Frequency Count*** 📊:
    - Use a vector<int> of size 26 to store the frequency of each letter 🅰️🅱️...
3. ***Count Odds*** 🔢:
Iterate over the frequency array to count characters with odd frequencies .
4. ***Decision***:
    - If cnt > k ➡️ false 🚫 (too many odd characters).
    - Otherwise, return true ✅.

---


# Complexity
- Time complexity:

       Iteration ->  O(n)

- Space complexity:

        O(1)

# Code
```cpp []
class Solution {
public:
    bool canConstruct(string s, int k) {
        if(s.size() < k) return false;
        vector<int> count (26, 0);
        for(char &c: s) {
            count[c - 'a']++;
        }

        int cnt = 0;
        for(int &val : count) {
            if(val%2) cnt++;
        }
        if(cnt > k) return false;
        return true;
    }
};
```
```java []
public class Solution {
    public boolean canConstruct(String s, int k) {
        if (s.length() < k) return false;
        int[] count = new int[26];
        for (char c : s.toCharArray()) {
            count[c - 'a']++;
        }
        
        int oddCount = 0;
        for (int val : count) {
            if (val % 2 != 0) oddCount++;
        }
        return oddCount <= k;
    }
}

```
```python []
class Solution:
    def canConstruct(self, s: str, k: int) -> bool:
        if len(s) < k:
            return False
        count = [0] * 26
        for c in s:
            count[ord(c) - ord('a')] += 1

        odd_count = sum(1 for val in count if val % 2 != 0)
        return odd_count <= k

```
```ruby []
def can_construct(s, k)
  return false if s.length < k
  
  count = Array.new(26, 0)
  s.each_char { |c| count[c.ord - 'a'.ord] += 1 }
  
  odd_count = count.count { |val| val.odd? }
  odd_count <= k
end

```
```javascript []
class Solution {
    canConstruct(s, k) {
        if (s.length < k) return false;
        const count = Array(26).fill(0);
        for (const c of s) {
            count[c.charCodeAt(0) - 'a'.charCodeAt(0)]++;
        }
        const oddCount = count.filter(val => val % 2 !== 0).length;
        return oddCount <= k;
    }
}

```
```typescript []
class Solution {
    canConstruct(s: string, k: number): boolean {
        if (s.length < k) return false;
        const count = Array(26).fill(0);
        for (const c of s) {
            count[c.charCodeAt(0) - 'a'.charCodeAt(0)]++;
        }
        const oddCount = count.filter(val => val % 2 !== 0).length;
        return oddCount <= k;
    }
}

```
```rust []
impl Solution {
    pub fn can_construct(s: String, k: i32) -> bool {
        if s.len() < k as usize {
            return false;
        }
        let mut count = [0; 26];
        for c in s.chars() {
            count[(c as usize) - ('a' as usize)] += 1;
        }
        let odd_count = count.iter().filter(|&&val| val % 2 != 0).count();
        odd_count <= k as usize
    }
}

```
```kotlin []
class Solution {
    fun canConstruct(s: String, k: Int): Boolean {
        if (s.length < k) return false
        val count = IntArray(26)
        for (c in s) {
            count[c - 'a']++
        }
        val oddCount = count.count { it % 2 != 0 }
        return oddCount <= k
    }
}

```
```dart []
class Solution {
    bool canConstruct(String s, int k) {
        if (s.length < k) return false;
        List<int> count = List.filled(26, 0);
        for (var c in s.runes) {
            count[c - 'a'.runes.first]++;
        }
        int oddCount = count.where((val) => val % 2 != 0).length;
        return oddCount <= k;
    }
}

```
```C# []
public class Solution {
    public bool CanConstruct(string s, int k) {
        if (s.Length < k) return false;
        int[] count = new int[26];
        foreach (char c in s) {
            count[c - 'a']++;
        }
        int oddCount = count.Count(val => val % 2 != 0);
        return oddCount <= k;
    }
}

```



['Hash Table', 'String', 'Greedy', 'Counting', 'C++', 'Java', 'TypeScript', 'Rust', 'JavaScript', 'Dart']