Solutions -  Count Odd Frequencies and Bit manipulation
IntuitionWe are given a string s composed of lowercase letters and an integer k. Our goal is to determine if it's possible to rearrange the characters of the st
# Intuition
We are given a string `s` composed of lowercase letters and an integer `k`. Our goal is to determine if it's possible to rearrange the characters of the string into exactly `k` palindromic substrings.

A palindrome is a string that reads the same forward and backward, showing symmetry with respect to its center.

# Approach
1. Handle initial edge cases, comparing the length of s to k.
- If the length of s is less than k, we return false, as we do not have enough characters to form k palindromes.
- If the length of s is equal to k, we return true, as we can simply use each character of s to form a palindrome.
2. Initialize:
- an array freq of size 26, representing the frequencies of each alphabetical character.
- an integer oddCount, representing the number of odd frequencies found in the string.
3. Iterate through s, incrementing the value of the index in freq corresponding to the character.
4. Iterate through the freq, incrementing oddCount when a frequency is odd.
5. Return true if oddCount is less than or equal to k; return false otherwise.

# Complexity
- Time complexity: O(N)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
We traverse the string of length n only once.
All other operations performed happen in constant time. This includes traversing freq, as the size of the array is a fixed size of 26.

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
The space required does not depend on the size of the input string, so only constant space is used.

Since we are limited to only lowercase letters in s, we can store the frequencies in constant space with an array of size 26, freq

# Code
```swift []
class Solution {
    func canConstruct(_ s: String, _ k: Int) -> Bool {
        if s.count < k { return false }
        if s.count == k { return true }
        var array = Array(repeating:0, count: 26)
        var oddCount = 0
        var charA = Character("a")
        for char in s {
            let index = char.asciiValue! - charA.asciiValue!
            let val = array[Int(index)]
            array[Int(index)] = val + 1
        }
        for count in array {
            if count % 2 == 1 {
                oddCount += 1
            }
        }
        return oddCount <= k
    }
}
```


# Approach
<!-- Describe your approach to solving the problem. -->
1. Handle initial edge cases, comparing the length of s to k.
- If the length of s is less than k, we return false, as we do not have enough characters to form k palindromes.
- If the length of s is equal to k, we return true, as we can simply use each character of s to form a palindrome.
2. Initialize an integer oddCount, which is used as a bitmask to track characters with odd frequencies
3. Iterate through s. For each character, we flip the bit tracking that character, with a set bit of 1 representing an odd frequency and a cleared bit 0 representing an even frequency
4. Return true if the number of 1 bits is less than or equal to k; return false otherwise.


# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
The loop iterates over each character in the string s, which takes O(n) time. The built-in function to count bits operates in O(1) time since it works on a fixed-size integer (32 bits). Therefore, the overall time complexity is dominated by the loop, resulting in O(n).

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
The space required does not depend on the size of the input string, so only constant space is used.

# Code
```swift []
class Solution {
    func canConstruct(_ s: String, _ k: Int) -> Bool {
        if s.count < k { return false }
        if s.count == k { return true }
        var oddCount = 0
        var charA = Character("a")
        for char in s {
            oddCount ^= 1 << (char.asciiValue! - charA.asciiValue!)
        }
        return oddCount.nonzeroBitCount <= k
    }
}
```
['Hash Table', 'String', 'Greedy', 'Swift', 'Counting']