C++ Palindrome Rearranging
#include <string>
#include <unordered_map>
bool palindromeRearranging(const std::string& inputString)
{
std::unordered_map<char, int> counts;
for (char c : inputString) {
++counts[c];
}
int oddCount = 0;
for (const auto& [ch, cnt] : counts) {
if (cnt % 2 != 0) {
++oddCount;
}
}
return oddCount <= 1;
}
This counts character frequency and checks whether the string has the right number of odd counts to form a palindrome.