Java 🍵 | Easy ✅ | Beats 95% 🔥 | TC: O(n) 📈 | SC: O(1) 🤯 - Optimal Solution
ComplexityCode
# Complexity

![image.png](https://assets.leetcode.com/users/images/2cbe0f64-6441-43ae-b432-64110d18bc0e_1736564531.0767372.png)

![image.png](https://assets.leetcode.com/users/images/fd1dfcc5-34c8-464a-8b5b-7f7871757be0_1736564521.8281696.png)



# Code
```java []
class Solution {
    public boolean canConstruct(String s, int k) {
        int n=s.length();
        if(k>n) return false;
        int freq[]=new int[26];
        int oddCount=0;
        for(int i=0;i<n;i++){
            freq[s.charAt(i)-'a']++;
        }
        for(int i=0;i<26;i++){
            if(freq[i]%2==1){
                oddCount++;
            }
        }
        if(oddCount>k) return false;
        return true;
    }
}
```

![image.png](https://assets.leetcode.com/users/images/c1861d1e-f304-4c91-9971-98962a970cef_1736564585.2212355.png)

['Hash Table', 'String', 'Greedy', 'Counting', 'Java']